8ms 5 lines C++ straightforward solution, easy to understand

  • 0

    It is not binary search, cost O(n) time. But it's very easy to understand.

    int findMin(vector<int>& nums) {
            int n = nums.size();
            for(int i=1; i<=n/2; ++i)
                if(nums[n-i]<nums[n-i-1]) return nums[n-i];
                if(nums[i]<nums[i-1]) return nums[i];
            return nums[0]; //no rotation or all the same numbers in the nums

Log in to reply

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