All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : June 15, 2024
Last updated : June 15, 2024
Related Topics : Array, Binary Search, Matrix
Acceptance Rate : 51.55 %
class Solution:
def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:
left, right = 0, len(matrix) * len(matrix[0]) - 1
while left < right :
mid = (left + right) // 2
row = mid // len(matrix[0])
col = mid % len(matrix[0])
if matrix[row][col] == target :
return True
if matrix[row][col] < target :
left = mid + 1
else :
right = mid
mid = (left + right) // 2
row = mid // len(matrix[0])
col = mid % len(matrix[0])
return matrix[row][col] == target