Follow up for "Search in Rotated Sorted Array": What if duplicates are allowed?
Would this affect the run-time complexity? How and why?
Write a function to determine if a given target is in the array.
class Solution { public: bool search(int A[], int n, int target) { if(n<=0) return false; int i = 0,j = n-1; if(target == A[i] || target == A[j]) return true; if(target>A[i]){ while(i<n-1 && target>A[i] && A[i]<=A[i+1]){ i++; if(target==A[i]) return true; } return false; }else if(target<A[j]){ while(j>0 && target<A[j] && A[j]>=A[j-1]){ j--; if(target==A[j]) return true; } return false; }//end if return false; } };