240. Search a 2D Matrix II
class Solution:
def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:
rows = len(matrix)
cols = len(matrix[0])
i = 0
j = cols - 1
while i < rows and j >= 0:
if matrix[i][j] == target:
return True
if matrix[i][j] < target:
i += 1
else:
j -= 1
return False