-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0034.py
30 lines (20 loc) · 796 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
class Solution:
def searchRange(self, nums, target: int):
if not nums:
return [-1, -1]
results = []
position = 0
def binarySearch(lst, position, results):
if len(lst) == 1:
if lst[0] == target:
results.append(position)
return
half = int(len(lst) / 2)
a = lst[:half]
b = lst[half:]
binarySearch(a, position, results)
binarySearch(b, position + half, results)
binarySearch(nums, position, results)
return [min(results), max(results)] if len(results) > 0 else [-1, -1]
solution = Solution().searchRange([], 0)
print(solution)