题目连接
81. 搜索旋转排序数组 II
题目思路
参考LeetCode 33的思想
代码实现
class Solution {
public boolean search(int[] nums, int target) {
int left = 0;
int right = nums.length - 1;
while(left <= right){
int mid = left + ((right - left) >> 1);
if(nums[mid] == target){
return true;
}
if(nums[mid] < nums[right]){
if(nums[mid] < target){
if(target <= nums[right]){
left = mid + 1;
}else{
right = mid - 1;
}
}else{
right = mid - 1;
}
}else if(nums[mid] > nums[right]){
if(nums[mid] < target){
left = mid + 1;
}else{
if(nums[right] < target){
right = mid - 1;
}else{
left = mid + 1;
}
}
}else{
right--;
}
}
return false;
}
}