240. 搜索二维矩阵 II - 力扣(LeetCode)
class Solution:def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:if not matrix or not matrix[0]:return Falsem, n = len(matrix), len(matrix[0])i, j = 0, n - 1 # 从右上角开始while i < m and j >= 0:if matrix[i][j] == target:return Trueelif matrix[i][j] > target:j -= 1 # 左移else:i += 1 # 下移return False