My c++ solution of O(lg(n)) time complexity.


  • 1
    E
     int findMin(vector<int> &num) {
        return Min(num,0,num.size()-1);
    }
    int Min(vector<int> &num,int begin,int end)
    {
        int ave = (begin + end)/2;
        if(end - begin <= 1)
        {
            if(num[end]<num[begin]) return num[end];
            else return num[begin];
        }
        else if(num[ave]>num[end]) return Min(num,ave,end);
        else return Min(num,begin,ave);
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.