public class Solution {
public boolean search(int[] A, int target) {
int l=0;
int r=A.length-1;
while(l<=r){
int m = (l+r)/2;
if (A[m] == target) return true;
if (A[m]<A[r]){
if (A[m]<target && target<=A[r]){
l=m+1;
}else{
r=m-1;
}
}else if (A[m]>A[r]){
if (A[l]<=target && target<A[m]){
r=m-1;
}else{
l=m+1;
}
// Find the first non-duplicate
}else{
r--;
}
}
return false;
}
}
Search in Rotated Sorted Array II
最新推荐文章于 2021-10-14 20:56:08 发布