classSolution: defsearchMatrix(self, matrix: List[List[int]], target: int) -> bool: m = len(matrix)-1 n = len(matrix[0])-1 left = 0 right = m while left<=right: mid = (left+right)>>1 if matrix[mid][0]==target or matrix[mid][n]==target: returnTrue elif matrix[mid][0] < target and target < matrix[mid][n]: # 继续二分 L = 0 R = n while L<=R: inner_mid = (L+R)>>1 if matrix[mid][inner_mid]==target: returnTrue elif target < matrix[mid][inner_mid]: R = inner_mid-1 elif matrix[mid][inner_mid] < target: L = inner_mid+1 returnFalse elif target < matrix[mid][0]: right = mid-1 else: left = mid+1 returnFalse