-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path33.py
More file actions
29 lines (26 loc) · 810 Bytes
/
33.py
File metadata and controls
29 lines (26 loc) · 810 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
class Solution(object):
def search(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: int
"""
start = 0
end = len(nums) - 1
while start <= end:
mid = (start + end) / 2
if nums[mid] == target:
return mid
if nums[mid] >= nums[start]:
if nums[mid] > target and nums[start] <= target:
end = mid - 1
else:
start = mid + 1
if nums[mid] < nums[end]:
if nums[mid] < target and nums[end] >= target:
start = mid + 1
else:
end = mid - 1
return -1
solu = Solution()
print solu.search([4, 5, 6, 7, 0, 1, 2, 3], 8)