Easy to understand C++ solution, run in 4ms


  • -1
    R

    class Solution {
    public:
    int findMin(vector<int>& nums) {

        std::size_t size = nums.size();
        
        if(size < 2){
            return nums[0];
        }
        
        // all number is in increasing order except at the boundary point
        for (auto i = 0; i < size-1; ++i){
            if (nums[i] > nums[i+1]){
                return nums[i+1];
            }
        }
        return nums[0];
    }
    

    };


Log in to reply
 

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