Note:
先把最后面重复的部分给他删去,然后走一遍二分查找旋转的点
在判断答案属于哪一边
然后再二分一遍答案
代码如下:
class Solution {
public:
bool search(vector<int>& nums, int target) {
if(nums.empty()) return false;
int R = nums.size() - 1;
while(R >= 0 && nums[R] == nums[0]) R --;
if(R < 0) return nums[0] == target;
int l = 0, r = R;
while(l < r){
int mid = l + r + 1 >> 1;
if(nums[mid] >= nums[0]) l = mid;
else r = mid - 1;
}
if(target >= nums[0]) r = l, l = 0;
else l ++, r = R;
while(l < r){
int mid = l + r >> 1;
if(nums[mid] >= target) r = mid;
else l = mid + 1;
}
return target == nums[r];
}
};