https://oj.leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/
Repetition is allowed, which means there will be a[l]==a[r], and A[mid]==a[r]. The latter is better to do, from the coordinate map to see the direct r=mid can.
The former will have a problem when a[mid]==a[r], it is not possible to determine the median position on the polyline, at this time degenerate into a linear search, so that l++. So the worst case scenario for this algorithm is O (n).
classSolution { Public: intn,m; intFindmin (vector<int> &num) {Vector<int> a=num; N=a.size (); intL=0; intr=n-1; while(l<R) { intMid= (L+R)/2; if(A[l]<a[r]) Break; Else if(a[l]>A[r]) { if(A[mid]>a[r]) l=mid+1; ElseR=mid; } Else { if(A[mid]>a[r]) l=mid+1; Else if(A[mid]<a[r]) r=mid; Elsel++; } } returnA[l]; }};
Leetcode-find Minimum in rotated Sorted array ii-rotate sorted array Find min-two points