-
Notifications
You must be signed in to change notification settings - Fork 481
/
0034.py
34 lines (31 loc) · 846 Bytes
/
0034.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class Solution:
def searchRange(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[int]
"""
l, r = 0, len(nums)
result = [-1,-1]
while l < r:
mid = (l+r)//2
if nums[mid] >= target:
if nums[mid] == target:
result[0] = mid
r = mid
else:
l = mid + 1
l, r = 0, len(nums)
while l < r:
mid = (l+r)//2
if nums[mid] > target:
r = mid
else:
if nums[mid] == target:
result[1] = mid
l = mid + 1
return result
if __name__ == "__main__":
nums = [5,7,7,8,8,10]
target = 6
print(Solution().searchRange(nums, target))