R4-二分查找专题
直接二维变一维,然后二分查找就可以了
python
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)