class Solution:
def searchRange(self, nums: List[int], target: int) -> List[int]:
left, right = 0, len(nums) - 1
answer = [-1, -1]
while left <= right:
if answer[0] != -1 and answer[1] != -1:
break
if target > nums[left]:
left += 1
elif target == nums[left]:
answer[0] = left
if target < nums[right]:
right -=1
elif target == nums[right]:
answer[1] = right
return answer
'CS > 알고리즘' 카테고리의 다른 글
[Leetcode] 74. Search a 2D Matrix (0) | 2023.05.01 |
---|---|
[Leetcode] 33. Search in Rotated Sorted Array (0) | 2023.05.01 |
[Leetcode] 17. Letter Combinations of a Phone Number (0) | 2023.05.01 |
[Leetcode] 16. 3Sum Closest (0) | 2023.05.01 |
[Leetcode] 15. 3Sum (0) | 2023.05.01 |