-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCycleFind.py
More file actions
31 lines (29 loc) · 795 Bytes
/
CycleFind.py
File metadata and controls
31 lines (29 loc) · 795 Bytes
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
def find(sou, target):
left = 0
right = len(sou) - 1
mid = (left + right) // 2
while left <= right:
if sou[left] == target:
return left
if sou[right] == target:
return right
if sou[mid] == target:
return mid
if sou[left] < sou[mid]:
if sou[left] < target < sou[mid]:
left += 1
right = mid - 1
else:
left = mid + 1
right -= 1
else:
if target > sou[left] or target < sou[right]:
left += 1
right = mid - 1
else:
left = mid + 1
right -= 1
mid = (left+right)//2
return -1
a = [8, 10, 20, 1, 3, 5, 6]
# print(find(a,))