File tree 2 files changed +23
-0
lines changed
2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change 35
35
66|[ Plus One] ( ./0066-plus-one.js ) |Easy|
36
36
67|[ Add Binary] ( ./0067-add-binary.js ) |Easy|
37
37
73|[ Set Matrix Zeroes] ( ./0073-set-matrix-zeroes.js ) |Medium|
38
+ 74|[ Search a 2D Matrix] ( ./0074-search-a-2d-matrix.js ) |Medium|
38
39
83|[ Remove Duplicates from Sorted List] ( ./0083-remove-duplicates-from-sorted-list.js ) |Easy|
39
40
88|[ Merge Sorted Array] ( ./0088-merge-sorted-array.js ) |Easy|
40
41
118|[ Pascal's Triangle] ( ./0118-pascals-triangle.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 74. Search a 2D Matrix
3
+ * https://leetcode.com/problems/search-a-2d-matrix/
4
+ * Difficulty: Medium
5
+ *
6
+ * Write an efficient algorithm that searches for a value in an m x n matrix.
7
+ * This matrix has the following properties:
8
+ *
9
+ * Integers in each row are sorted from left to right.
10
+ * The first integer of each row is greater than the last integer of the previous row.
11
+ */
12
+
13
+ /**
14
+ * @param {number[][] } matrix
15
+ * @param {number } target
16
+ * @return {boolean }
17
+ */
18
+ var searchMatrix = function ( matrix , target ) {
19
+ return matrix
20
+ . filter ( row => row [ 0 ] <= target && row [ row . length - 1 ] >= target )
21
+ . find ( row => row . includes ( target ) ) !== undefined ;
22
+ } ;
You can’t perform that action at this time.
0 commit comments