Python Solution -- 85ms (beats 94.89%)


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

Log in to reply
 

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