-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.py
More file actions
25 lines (22 loc) · 759 Bytes
/
Copy pathSolution.py
File metadata and controls
25 lines (22 loc) · 759 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
from _ast import List
class Solution:
def search(self, nums: List[int], target: int) -> int:
if nums is None or len(nums) == 0:
return -1
start = 0
end = len(nums) - 1
while start <= end:
medium = (start + end) >> 1;
if nums[medium] == target:
return medium
if nums[start] <= nums[medium]:
if nums[start] <= target and target < nums[medium]:
end = medium - 1
else:
start = medium + 1
else:
if nums[medium] < target and target <= nums[end]:
start = medium + 1
else:
end = medium - 1
return -1