81.搜索旋转排序数组Ⅱ
class Solution {
public boolean search(int[] nums, int target) {
int n=nums.length;
if(n==0){
return false;
}
if(n==1){
return nums[0]==target?true:false;
}
int left=0;
int right=n-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(nums[0]<=target&&target<nums[mid]){
right-=1;
}else{
left+=1;
}
}else{
if(nums[mid]<target&&target<=nums[right]){
left+=1;
}else{
right-=1;
}
}
}
return false;
}
}