题目:
题解:
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-1while row_l <= row_r:m = (row_l+row_r)//2if target < matrix[m][0]:row_r = m-1elif target > matrix[m][0]:row_l = m+1elif target == matrix[m][0]:return Trueif row_r == 0 and matrix[row_r][0] > target:return Falsecol_l,col_r = 0,col-1while col_l <= col_r:m = (col_l+col_r)//2if target < matrix[row_r][m]:col_r = m-1elif target > matrix[row_r][m]:col_l = m+1elif target == matrix[row_r][m]:return Truereturn False