题目:
题解:
class Solution:
def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:
row,col = len(matrix),len(matrix[0])
row_l,row_r = 0,row-1
while row_l <= row_r:
m = (row_l+row_r)//2
if target < matrix[m][0]:
row_r = m-1
elif target > matrix[m][0]:
row_l = m+1
elif target == matrix[m][0]:
return True
if row_r == 0 and matrix[row_r][0] > target:
return False
col_l,col_r = 0,col-1
while col_l <= col_r:
m = (col_l+col_r)//2
if target < matrix[row_r][m]:
col_r = m-1
elif target > matrix[row_r][m]:
col_l = m+1
elif target == matrix[row_r][m]:
return True
return False