文章作者:Tyan
博客:noahsnail.com | CSDN | 简书
1. Description
2. Solution
class Solution {
public:bool search(vector<int>& nums, int target) {int size = nums.size();int left = 0;int right = size - 1;while(left <= right) {int mid = (left + right) / 2;if(nums[mid] == target) {return true;}if(nums[left] == nums[mid]) {left++;continue;}if(nums[left] < nums[mid]) {if(target >= nums[left] && target <= nums[mid]) {right = mid - 1;}else {left = mid + 1;}}else {if(target >= nums[mid] && target <= nums[right]) {left = mid + 1;}else {right = mid - 1;}}}return false;}
};
Reference
- https://leetcode.com/problems/search-in-rotated-sorted-array-ii/description/