My concise solution with 8ms


  • 0
    B

    class Solution {
    public:

    int findMin(vector<int>& nums) {
        
        int left = 0, right = nums.size()-1;
        
        while(left < right)
        {
            while(left < right && nums[left] == nums[left + 1]) left++;  //Remove duplicate nums in head and tail
            while(right > left && nums[right] == nums[right - 1]) right--;
                    
            int mid = left + (right - left)/2;
            
            if(nums[mid] > nums[0])
            {
                if(nums[mid] <= nums[nums.size()-1])
                {
                    return nums[0];
                }
                
                left = mid + 1;
            } 
            else if(nums[mid] < nums[0])
            {
                right = mid;
            }
            else
            {
                return min(nums[left], nums[right]);
            }
        }
        
        return nums[left];
    }
    

    };


Log in to reply
 

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