Loading

[矩阵]搜索二维矩阵II

class Solution:
    def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:

        n = len(matrix)
        m = len(matrix[0])

        row = 0
        col = m-1

        while row <= n-1 and col >= 0:
            if matrix[row][col] == target:
                return True
            elif matrix[row][col] > target:
                col -= 1
            else:
                row += 1
        
        return False
 
        
posted @ 2024-09-20 13:22  Duancf  阅读(18)  评论(0)    收藏  举报