5 lines C++ implementation


  • 7
    class Solution {
    public:
        int findMin(vector<int>& nums) {
            int start=0, end=nums.size()-1;
            while(end>start){
                int mid=start+(end-start)/2;
                if(nums[mid]<nums[end]) end=mid;
                else start=mid+1;
            }
            return nums[start];
        }
    };

Log in to reply
 

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