Search a 2D Matrix II
[
[1, 4, 7, 11, 15],
[2, 5, 8, 12, 19],
[3, 6, 9, 16, 22],
[10, 13, 14, 17, 24],
[18, 21, 23, 26, 30]
]class Solution(object):
def searchMatrix(self, matrix, target):
if matrix == None or len(matrix) == 0:
return False
row, col = 0, len(matrix[0]) - 1
while row < len(matrix) and col >= 0:
if matrix[row][col] == target:
return True
elif target < matrix[row][col]:
col -=1
else:
row +=1
return FalseLast updated