leetcode74Search a 2D Matrix

xiaoxiao2021-02-28  97

class Solution(object):     def searchMatrix(self, matrix, target):         """         :type matrix: List[List[int]]         :type target: int         :rtype: bool         """         if not matrix:             return False         n=len(matrix)         m=len(matrix[0])         l,r=0,n*m-1         while l<=r:             mid=l+(r-l)/2             e=matrix[mid/m][mid%m]             if e==target:                 return True             elif e<target:                 l=mid+1             else:                 r=mid-1         return False
转载请注明原文地址: https://www.6miu.com/read-45314.html

最新回复(0)