Solution beats 88% of python submissions


  • 0
    T

    There were no solutions posted, thought will post here for others. Please post a better solution here if you have.

    class Solution(object):
        def searchMatrix(self, matrix, target):
            """
            :type matrix: List[List[int]]
            :type target: int
            :rtype: bool
            """
            
            # 1. check last element of all the rows. if num > target
            # 2. o(n) complexity
            target_row = []
    
            for row in matrix:
                if len(row):
                        if row[-1] >= int(target):
                        target_row = row
                        break
    
            return True if target in target_row else False
            
                    
    

Log in to reply
 

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