二分查找
class Solution {
int n;
bool dfs(vector<int>nums,int i,int j,int target)
{
if(i>j) return false;
int mid=i+(j-i)/2;
if(nums[mid]==target) return true;
if(nums[i]==nums[j]&&nums[j]==nums[mid]) return dfs(nums,i+1,j-1,target);
if(nums[i]<=nums[mid]){
if(nums[i]<=target&&target<nums[mid]) return dfs(nums,i,mid-1,target);
else return dfs(nums,mid+1,j,target);
}
else{
if(nums[mid]<target&&target<=nums[n])
return dfs(nums,mid+1,j,target);
else return dfs(nums,i,mid-1,target);
}
return false;
}
public:
bool search(vector<int>& nums, int target) {
n=nums.size()-1;
if(n==-1) return false;
if(n==0) return nums[0]==target;
return dfs(nums,0,n,target);}
};