Solution:
# T:O(m+n) S:O(1) class Solution(object): def searchMatrix(self, matrix, target): """ :type matrix: List[List[int]] :type target: int :rtype: bool """ m, n = len(matrix), len(matrix[0]) i, j = 0, n - 1 while i < m and j > -1: if matrix[i][j] == target: return True elif matrix[i][j] > target: j -= 1 else: i += 1 return FalseRun Time: 128 ms
No comments:
Post a Comment