-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path33.cpp
31 lines (29 loc) · 759 Bytes
/
33.cpp
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
class Solution {
public:
int search1(vector<int>nums,int s,int e,int key){
if(s>e){
return -1;
}
int mid=(s+e)/2;
if(key==nums[mid]){
return mid;
}
if(nums[s]<= nums[mid]){
if(key<=nums[mid] && key>=nums[s]){
return search1(nums,s,mid-1,key);
}
else {
return search1(nums,mid+1,e,key);
}
}
if(key>=nums[mid] && key<=nums[e]){
return search1(nums,mid+1,e,key);
}
return search1(nums,s,mid-1,key);
}
int search(vector<int>& nums, int target) {
int n=nums.size();
int y=search1(nums,0,n-1,target);
return y;
}
};