-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path33.py
More file actions
22 lines (19 loc) · 682 Bytes
/
Copy path33.py
File metadata and controls
22 lines (19 loc) · 682 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Solution(object):
def search(self, nums, target):
if not nums: return -1
start, end = 0, len(nums) - 1
while start <= end:
mid = start + ((end - start) >> 1)
if nums[mid] == target:
return mid
if nums[start] <= nums[mid]:
if nums[start] <= target and target < nums[mid]:
end = mid - 1
else:
start = mid + 1
elif nums[mid] <= nums[end]:
if nums[mid] < target and target <= nums[end]:
start = mid + 1
else:
end = mid - 1
return -1