Skip to content

Commit d39a71f

Browse files
add 74
1 parent 50da0d5 commit d39a71f

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ LeetCode
5454
|0070|[Climbing Stairs](https://leetcode.com/problems/climbing-stairs/) | c | [c++](./src0070-Climbing-Stairs/0070.cpp) |[python](./src/0070-Climbing-Stairs/0070.py)|||Easy|
5555
|0071|[Simplify Path](https://leetcode.com/problems/simplify-path/) | c | [c++](./src/0071-Simplify-Path/0071.cpp) |[python](./src/0071-Simplify-Path/0071.py)|||Medium|
5656
|0073|[Set Matrix Zeroes](https://leetcode.com/problems/set-matrix-zeroes/) | c | [c++](./src/0073-Set-Matrix-Zeroes/0073.cpp) |[python](./src/0073-Set-Matrix-Zeroes/0073.py)|||Medium|
57+
|0074|[Search a 2D Matrix](https://leetcode.com/problems/search-a-2d-matrix/) | c | [c++](./src/0074-Search-a-2D-Matrix/0074.cpp) |[python](./src/0074-Search-a-2D-Matrix/0074.py)|||Medium|
5758
|0075|[Sort Colors](https://leetcode.com/problems/sort-colors/) | c | [c++](./src/0075-Sort-Colors/0075.cpp) |[python](./src/0075-Sort-Colors/0075.py)|||Medium|
5859
|0076|[Minimum Window Substring](https://leetcode.com/problems/minimum-window-substring/) | c | [c++](./src/0076-Minimum-Window-Substring/0076.cpp) |[python](./src/0076-Minimum-Window-Substring/0076.py)|||Easy|
5960
|0077|[Combinations](https://leetcode.com/problems/combinations/) | c | [c++](./src/0077-Combinations/0077.cpp) |[python](./src/0077-Combinations/0077.py)|||Medium|

src/0074-Search-a-2D-Matrix/0074.cpp

Whitespace-only changes.

src/0074-Search-a-2D-Matrix/0074.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import bisect
2+
class Solution:
3+
def searchMatrix(self, matrix, target):
4+
"""
5+
:type matrix: List[List[int]]
6+
:type target: int
7+
:rtype: bool
8+
"""
9+
i = bisect.bisect(matrix, [target])
10+
if i < len(matrix) and matrix[i][0] == target:
11+
return True
12+
row = matrix[i-1]
13+
j = bisect.bisect_left(row, target)
14+
return j < len(row) and row[j] == target
15+
16+
17+
if __name__ == "__main__":
18+
matrix = [
19+
[1, 3, 5, 7],
20+
[10, 11, 16, 20],
21+
[23, 30, 34, 50]
22+
]
23+
target = 13
24+
print(Solution().searchMatrix(matrix, target))

0 commit comments

Comments
 (0)