My C++ solution to solve it


  • 0
    N
    class Solution {
    public:
        int findMin(vector<int> &num) {
            int first=0;
            int last=num.size()-1;
            while(first<last){
                if(num[first]<num[last])
                    return num[first];
                int mid=(first+last)/2;
                if(num[mid]>num[mid+1])
                    return num[mid+1];
                if(num[mid]<num[last])
                    last=mid;
                else{
                    if(num[mid]>num[first])
                        first=mid+1;
                    else  //last<=mid<=first
                        first++;
                }    
            }
            return num[first];
        }
    };

Log in to reply
 

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