![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/2ff41a0ccb0b6e085245eb1149cf1384.png#pic_center)
class Solution {
public:
bool search(vector<int>& nums, int target) {
if(nums.size() == 0)
return false;
int start = 0, end = nums.size() - 1;
int mid;
while(start <= end){
mid = start + (end - start) / 2;
if(nums[mid] == target)
return true;
if(nums[start] == nums[mid]){
start++;
continue;
}
if(nums[start] < nums[mid]){
if(nums[mid] > target && nums[start] <= target)
end = mid - 1;
else
start = mid + 1;
}else{
if(nums[mid] < target && nums[end] >= target)
start = mid + 1;
else
end = mid - 1;
}
}
return false;
}
};
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/1ee030d505e2473a3e12b1f195220b8d.png#pic_center)
class Solution {
public:
int search(vector<int>& nums, int target) {
if(nums.size() == 0)
return -1;
int start = 0, end = nums.size() - 1;
while(start <= end){
int mid = start + (end - start) / 2;
if(nums[mid] == target)
return mid;
if(nums[start] <= nums[mid]){
if(target >= nums[start] && target < nums[mid])
end = mid - 1;
else
start = mid + 1;
}
else{
if(target > nums[mid] && target <= nums[end])
start = mid + 1;
else
end = mid - 1;
}
}
return -1;
}
};