My solution in O(logn) time O(1) space 40ms


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

    }


  • 0
    M

    it will be O(n) if the input is{10,10,10,10,10,10,10,10}.


Log in to reply
 

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