Skip to main content

74. Search a 2D Matrix

link

class Solution:
def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:

m = len(matrix)
n = len(matrix[0])

idx = bisect_left([matrix[i][-1] for i in range(m)], target)

if idx == m:
return False


idx2 = bisect_left(matrix[idx], target)

if idx2 == n:
return False

return matrix[idx][idx2] == target