File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 1+ #Runtime: 36 ms, faster than 95.27% of Python3 online submissions for Search a 2D Matrix.
2+ #Memory Usage: 14.7 MB, less than 86.50% of Python3 online submissions for Search a 2D Matrix.
3+
4+ class Solution :
5+ def searchMatrix (self , matrix : List [List [int ]], target : int ) -> bool :
6+ i_index = - 2
7+ if target > matrix [- 1 ][- 1 ]:
8+ return False
9+ for i in range (len (matrix )):
10+ if target == matrix [i ][0 ]:
11+ return True
12+ if target < matrix [i ][0 ]:
13+ i_index = i - 1
14+ break
15+ if i_index == - 2 :
16+ i_index = len (matrix ) - 1
17+ if i_index == - 1 :
18+ return False
19+ for i in range (len (matrix [0 ])):
20+ if target == matrix [i_index ][i ]:
21+ return True
22+ if target < matrix [i_index ][i ]:
23+ return False
24+ return False
You can’t perform that action at this time.
0 commit comments