3ms easy understand C++ solution


  • 0
    R
    class Solution {
    public:
        int findMin(vector<int>& nums) {
            for(int i = 0; i < nums.size()-1; ++i)
            {
                if(nums[i] > nums[i+1])
                    return nums[i+1];
            }
            return nums[0];
        }
    };
    

    This code only works with no duplicate.


Log in to reply
 

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