马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
240. 搜刮二维矩阵 II - 力扣(LeetCode)
- class Solution:
- def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:
- if not matrix or not matrix[0]:
- return False
- m, n = len(matrix), len(matrix[0])
- i, j = 0, n - 1 # 从右上角开始
- while i < m and j >= 0:
- if matrix[i][j] == target:
- return True
- elif matrix[i][j] > target:
- j -= 1 # 左移
- else:
- i += 1 # 下移
- return False
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |