Online Judge Solutions

Sunday, November 2, 2014

Find Minimum in Rotated Sorted Array

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

No comments:

Post a Comment