【hot100篇-python刷题记录】【搜索二维矩阵】
R6-二分查找篇
印象题,直接把它转成一维来处理。
class Solution:
def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:
nums=[i for row in matrix for i in row]
def binfind(the,target):
low,high=0,len(the)-1
while low<=high:
mid=(low+high)//2
if the[mid]==target:
return True
elif the[mid]>target:
high=mid-1
else:
low=mid+1
return False
return binfind(nums,target)