Analysis:
For Target>a[mid]:
There is only one case that we should seach [Start,mid-1]: Peak was in the left, i.e., A[start]>a[mid] && target >=a[start].
For Target<a[mid]:
There is only one case that we should search [Mid+1,end]: Peak was in the right, i.e., A[end]<a[mid] && TARGET&L T;=a[end].
Solution:
1 Public classSolution {2 Public BooleanSearchint[] A,inttarget) {3 returnSearchrecur (a,target,0,a.length-1);4 }5 6 Public BooleanSearchrecur (int[] A,intTargetintStartintend) {7 if(Start>end)return false;8 9 intMid = (start+end)/2;Ten if(A[mid]==target)return true; One A if(A[start]==a[mid] && a[end]==A[mid]) - return(Searchrecur (a,target,start,mid-1) | | searchrecur (a,target,mid+1, end)); - the if(target>A[mid]) - if(A[start]>a[mid] && target>=A[start]) - returnSearchrecur (a,target,start,mid-1); - Else returnSearchrecur (a,target,mid+1, end); + Else - if(A[end]<a[mid] && target<=A[end]) + returnSearchrecur (a,target,mid+1, end); A Else returnSearchrecur (a,target,start,mid-1); at - } - - -}
Leetcode-search in rotated Sorted Array II