Slightly Better !


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

Log in to reply
 

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