-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20leet74-2.py
More file actions
28 lines (27 loc) · 740 Bytes
/
20leet74-2.py
File metadata and controls
28 lines (27 loc) · 740 Bytes
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
# Python TR
# Time:2021/9/19 3:23 下午
# coding = utf-8
class Solution(object):
def searchMatrix(self, matrix, target):
"""
:type matrix: List[List[int]]
:type target: int
:rtype: bool
"""
if matrix==None or len(matrix)==0:
return False
w = len(matrix[0])
h = len(matrix)
row = 0
col = w-1
# while row<h-1 and col>=0:
while row<h-1 and matrix[row][col]<target:
row+=1
while col>=0 and matrix[row][col]>target:
col-=1
if matrix[row][col]==target:
return True
return False
s = Solution()
nums = [[1,3,5,7],[10,11,16,20],[23,30,34,60]]
print(s.searchMatrix(nums,13))