python leetcode 240. Search a 2D Matrix II

class Solution(object):
    def searchMatrix(self, matrix, target):
        """
        :type matrix: List[List[int]]
        :type target: int
        :rtype: bool
        """
        m = len(matrix)
        if  m==0:
            return False
        n = len(matrix[0])
        
        i=0
        j=n-1
        while i<m and j>=0:
            if target == matrix[i][j]:
                return True 
            elif target > matrix[i][j]:
                i+=1 
            else:
                j-=1
        return False

猜你喜欢

转载自blog.csdn.net/Neekity/article/details/85091420