力扣 240. 搜索二维矩阵II

解法

1
2
3
4
5
6
7
8
9
10
11
12
def searchMatrix(matrix, target):
ret = False
m, n = len(matrix), len(matrix[0])
i, j = 0, n - 1
while not ret and i < m and j > -1:
if matrix[i][j] == target:
ret = True
elif matrix[i][j] < target:
i += 1
else:
j -= 1
return ret
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2022 eightyninth
  • Visitors: | Views:

请我喝杯咖啡吧~

支付宝
微信