先排除 大于[-1][-1] 小于[0][0] 和空阵
然后从左下角开始找
因为 存在于矩阵中的数 比最下角大的都在左下角右边 比左下角小的都在坐下角上面
这样 如果左下为目标 则true
如果左下角大于目标 则最后一行排除
若左下角小于目标则最左一列排除
class Solution:
def searchMatrix(self, matrix, target):
"""
:type matrix: List[List[int]]
:type target: int
:rtype: bool
"""
"""
:type matrix: List[List[int]]
:type target: int
:rtype: bool
"""
m = len(matrix)
if m == 0:
return False
n = len(matrix[0])
if n == 0:
return False
i = m - 1
j = 0
while i >= 0 and j < n:
if matrix[i][j] == target:
return True
elif matrix[i][j] < target:
j = j + 1
else:
i = i - 1
return False