My slow but accepted python recursive solution, need to be improved


  • 0
    M
    class Solution(object):
        def searchMatrix(self, matrix, target):
            """
            :type matrix: List[List[int]]
            :type target: int
            :rtype: bool
            """
            if len(matrix) == 0:
                return False
            if len(matrix) == 1:
                if target not in matrix[0]:
                    return False
                else:
                    return True
            if target > max(matrix[0]):
                return self.searchMatrix(matrix[1:],target)
            elif target == max(matrix[0]):
                return True
            else:
                if target in matrix[0]:
                    return True
                else:
                    return self.searchMatrix(matrix[1:],target)

Log in to reply
 

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