My Solution,13ms


  • 0
    C

    class Solution {
    public:
    int findMin(vector<int>& nums) {
    int size = nums.size();

        int L = 0, R = size-1;
        if(nums[R] > nums[L]) return nums[L];
    
        while(L < R){
            int M = (L + R) / 2;
            if(nums[M] == nums[R] || nums[M] == nums[L]){
                int mi=nums[L];
                for(int i=L+1;i<=R;i++){
                    mi = min(mi,nums[i]);
                }
    
                return mi;
            }else if(nums[M] > nums[R]) L = M +1;
            else R = M;
        }
    
        return nums[L];
    }
    

    };


Log in to reply
 

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