Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from typing import List
- class Solution:
- def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:
- left = 0
- right = len(matrix) * len(matrix[0]) - 1
- rows = len(matrix)
- cols = len(matrix[0])
- while left <= right:
- mid = (left + right) // 2
- row_idx = mid // cols
- col_idx = mid % cols
- value = matrix[row_idx][col_idx]
- if value == target:
- return True
- elif value > target:
- right = mid - 1
- else:
- left = mid + 1
- return False
Advertisement
Add Comment
Please, Sign In to add comment