-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path34python3.py
42 lines (40 loc) · 1.03 KB
/
34python3.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
35
36
37
38
39
40
41
42
'''
XXXXXX ttttt yyyyyy
if [mid] != t : Binary S
if [mid] == t :
find start
right = mid
find end
left = mid
'''
class Solution:
def searchRange(self, nums: List[int], target: int) -> List[int]:
res = [-1, -1]
if not len(nums):
return res
s_point, e_point = -1, -1
left, right = 0, len(nums)-1
while left < right:
# find the s_point
mid = left + right >> 1
if nums[mid] >= target:
right = mid
else:
left = mid+1
#end_while
if nums[left] == target:
s_point = left
if s_point == -1:
return res
left, right = 0, len(nums)-1
while left < right:
# find the e_point
mid = left + right + 1 >> 1
if nums[mid] > target:
right = mid-1
else:
left = mid
#end_while
e_point = left
res = [s_point, e_point]
return res