class Solution:
def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:
if not matrix or not matrix[0]:
return False
m = len(matrix)
n = len(matrix[0])
i = m-1
j = 0
while 0<= i < m and 0 <= j < n:
mid = matrix[i][j]
if mid > target:
i -= 1
elif mid < target:
j += 1
else:
return True
return False
每日一道Leetcode - 74. 搜索二维矩阵
最新推荐文章于 2025-03-26 15:51:13 发布