gary@interview:~/interview/coding/240-search-a-2d-….md$
$ cat ./coding/240-search-a-2d-matrix-ii.md
[Coding]

240. Search a 2D Matrix II

────────────────────────────────────────────────────────────

240. Search a 2D Matrix II

class Solution:
    def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:
        rows = len(matrix)
        cols = len(matrix[0])
    
        i = 0
        j = cols - 1
        while i < rows and j >= 0:
            if matrix[i][j] == target:
                return True
            if matrix[i][j] < target:
                i += 1
            else:
                j -= 1
        return False

類似題目 74. Search a 2D Matrix

$ ls ./coding/ | grep -v 240-search-a-2d-matrix-ii
265. Paint House II256. Paint House143. Reorder List1762. Buildings With an Ocean View
← cd ../codingcd ~