-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlintcode_63.py
More file actions
35 lines (34 loc) · 1018 Bytes
/
lintcode_63.py
File metadata and controls
35 lines (34 loc) · 1018 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
32
33
34
35
class Solution:
"""
@param A: an integer ratated sorted array and duplicates are allowed
@param target: An integer
@return: a boolean
"""
def search(self, A, target):
# write your code here
if A == None or len(A) < 1:
return False
start = 0
end = len(A) - 1
while start + 1 < end:
mid = start + (end - start) // 2
if A[mid] == target:
return True
if A[mid] > A[start]:
if target >= A[start] and target < A[mid]:
end = mid
else:
start = mid
elif A[mid] < A[end]:
if target <= A[end] and target > A[mid]:
start = mid
else:
end = mid
else:
start = start + 1
if A[start] == target:
return True
elif A[end] == target:
return True
else:
return False