File tree 2 files changed +26
-0
lines changed
2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 216
216
237|[ Delete Node in a Linked List] ( ./0237-delete-node-in-a-linked-list.js ) |Easy|
217
217
238|[ Product of Array Except Self] ( ./0238-product-of-array-except-self.js ) |Medium|
218
218
239|[ Sliding Window Maximum] ( ./0239-sliding-window-maximum.js ) |Hard|
219
+ 240|[ Search a 2D Matrix II] ( ./0240-search-a-2d-matrix-ii.js ) |Medium|
219
220
242|[ Valid Anagram] ( ./0242-valid-anagram.js ) |Easy|
220
221
257|[ Binary Tree Paths] ( ./0257-binary-tree-paths.js ) |Easy|
221
222
258|[ Add Digits] ( ./0258-add-digits.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 240. Search a 2D Matrix II
3
+ * https://leetcode.com/problems/search-a-2d-matrix-ii/
4
+ * Difficulty: Medium
5
+ *
6
+ * Write an efficient algorithm that searches for a value target in an m x n integer matrix
7
+ * matrix. This matrix has the following properties:
8
+ * - Integers in each row are sorted in ascending from left to right.
9
+ * - Integers in each column are sorted in ascending from top to bottom.
10
+ */
11
+
12
+ /**
13
+ * @param {number[][] } matrix
14
+ * @param {number } target
15
+ * @return {boolean }
16
+ */
17
+ var searchMatrix = function ( matrix , target ) {
18
+ for ( let i = 0 , j = matrix [ 0 ] . length - 1 ; i < matrix . length && j >= 0 ; ) {
19
+ if ( matrix [ i ] [ j ] === target ) {
20
+ return true ;
21
+ }
22
+ matrix [ i ] [ j ] > target ? j -- : i ++ ;
23
+ }
24
+ return false ;
25
+ } ;
You can’t perform that action at this time.
0 commit comments