Accepted O(m+n) in Python


  • 0
    X
    class Solution:
        # @param {integer[][]} matrix
        # @param {integer} target
        # @return {boolean}
        def searchMatrix(self, matrix, target):
            j = len(matrix[0])-1;i=0
            while i < len(matrix) and j >= 0:
                if matrix[i][j] == target:
                    return True
                elif matrix[i][j] > target:
                    j -= 1
                else:
                    i += 1
            return False

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.