81. 搜索旋转排序数组 II
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/4a71189a9ea8612e840f37ce7730a9be.png)
class Solution {
public:
bool search(vector<int>& nums, int target, int left, int right) {
if(left > right) return false;
int mid = (left + right) >> 1;
if(nums[mid] == target) return true;
if(nums[left] == nums[right]) return search(nums, target, left + 1, right);
if(nums[left] <= nums[mid]) {
if(nums[left] <= target && target < nums[mid]) return search(nums, target, left, mid - 1);
else return search(nums, target, mid + 1, right);
}
if(nums[mid] < target && target <= nums[right]) return search(nums, target, mid + 1, right);
return search(nums, target, left, mid - 1);
}
bool search(vector<int>& nums, int target) {
return search(nums, target, 0, nums.size() - 1);
}
};
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/3352e84f66974a6de0a79f237b90510f.png)
class Solution {
public:
bool search(vector<int>& nums, int target) {
for(auto num : nums) if(num == target) return true;
return false;
}
};