Clean C++ ac codes, with binary search.


  • 0
    S
    int findMin(vector<int>& nums) {
            int l = 0, r = nums.size()-1,ans=nums[0];
            while(l <= r){
                int mid = l + ((r - l)>>1);
                if(nums[mid] >= nums[r])  l = mid+1;
                else r = mid-1;
                if(ans > nums[mid])  ans = nums[mid];
            }
            return ans;
        }

Log in to reply
 

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