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