Online Judge Solutions

Sunday, November 2, 2014

Find Minimum in Rotated Sorted Array II

 
   int findMin(vector<int> &A) {
        int l = 0, r = A.size()-1;
        while(l < r) {
            if (A[l] < A[r])
              break;
            int m = l + (r-l)/2;
           
            if (A[m] < A[r])
                r = m;
            else if (A[m] > A[r])
                l = m+1;
            else {
               r--;
               l++;
            }
        }       
        return A[l];
    }

No comments:

Post a Comment