Skip to content

Latest commit

 

History

History
25 lines (22 loc) · 593 Bytes

P112. 搜索二维矩阵.md

File metadata and controls

25 lines (22 loc) · 593 Bytes

algo48

class Solution(object):
    def searchMatrix(self, matrix, target):
        """
        :type matrix: List[List[int]]
        :type target: int
        :rtype: bool
        """

        row = len(matrix)-1
        col = 0
        #从左下角或右上角开始搜索
        start = matrix[row][col]

        while (row>=0 and col < len(matrix[0])):
            if matrix[row][col] < target:
                col += 1
            elif matrix[row][col] > target:
                row -= 1
            else:
                return True
        return False