class Solution:
def searchMatrix(self, matrix: List[List[int]], target: int) -> bool:
for line in matrix:
left, right = 0, len(line) - 1
while left <= right:
mid = left + (right - left) // 2
if line[mid] == target:
return True
if target < line[mid]:
right = mid - 1
else:
left = mid + 1
return False
while left < right: 인 경우
원소가 하나인 경우를 탐색하지 못한다.
'CS > 알고리즘' 카테고리의 다른 글
[Leetcode] 162. Find Peak Element (0) | 2023.05.02 |
---|---|
[Leetcode] 153. Find Minimum in Rotated Sorted Array (0) | 2023.05.02 |
[Leetcode] 33. Search in Rotated Sorted Array (0) | 2023.05.01 |
[Leetcode] 34. Find First and Last Position of Element in Sorted Array (0) | 2023.05.01 |
[Leetcode] 17. Letter Combinations of a Phone Number (0) | 2023.05.01 |