- 32ms
- 82%
class Solution:
def searchMatrix(self, matrix, target):
"""
:type matrix: List[List[int]]
:type target: int
:rtype: bool
"""
if not matrix: return False
m = len(matrix)
n = len(matrix[0])
i,j = 0,n-1
while i<m and j>=0:
if target>matrix[i][j]: i+=1
elif target<matrix[i][j]: j-=1
else: return True
return False