Skip to content

Commit e47c80f

Browse files
committed
Add solution #74
1 parent 58b6b5d commit e47c80f

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
66|[Plus One](./0066-plus-one.js)|Easy|
3636
67|[Add Binary](./0067-add-binary.js)|Easy|
3737
73|[Set Matrix Zeroes](./0073-set-matrix-zeroes.js)|Medium|
38+
74|[Search a 2D Matrix](./0074-search-a-2d-matrix.js)|Medium|
3839
83|[Remove Duplicates from Sorted List](./0083-remove-duplicates-from-sorted-list.js)|Easy|
3940
88|[Merge Sorted Array](./0088-merge-sorted-array.js)|Easy|
4041
118|[Pascal's Triangle](./0118-pascals-triangle.js)|Easy|

solutions/0074-search-a-2d-matrix.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
};

0 commit comments

Comments
 (0)