share my 0ms solution in C++


  • 0
    C

    '''
    class Solution {
    public:
    int wiggleMaxLength(vector<int>& nums) {
    if(nums.size()==0) return 0;
    if(nums.size()==1) return 1;
    int ret = 0,pivot = nums[0];
    int inc = 0;
    for(int i=1;i<nums.size();i++){
    if(nums[i]==nums[i-1]) continue;
    else if(nums[i]>nums[i-1]){
    if(inc==-1||inc==0){
    ret++;
    pivot = nums[i];
    inc = 1;
    }
    }
    else{
    if(inc==1||inc==0){
    ret++;
    pivot = nums[i];
    inc = -1;
    }
    }
    }
    return ret+1;
    }
    };
    '''


Log in to reply
 

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