-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathanswer.py
28 lines (23 loc) · 814 Bytes
/
answer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env python3
#-------------------------------------------------------------------------------
# Solution
#-------------------------------------------------------------------------------
class Solution(object):
def searchMatrix(self, matrix, target):
"""
:type matrix: List[List[int]]
:type target: int
:rtype: bool
"""
if not matrix:
return False
i, j = 0, len(matrix[0])-1
while 0 <= i < len(matrix) and 0 <= j < len(matrix[0]):
if matrix[i][j] == target:
return True
elif matrix[i][j] < target:
i += 1
else:
j -= 1
return False
#-------------------------------------------------------------------------------