share my 0ms concise c++ code


  • 0
    Z
    int wiggleMaxLength(vector<int>& nums) {
            if(nums.empty())return 0;
            int wiggle[2],len[2];
            wiggle[0]=0,wiggle[1]=1;
            len[0]=len[1]=1;
            for(int i=1;i<nums.size();i++){
                for(int j=0;j<2;j++){
                    if(wiggle[j]&&nums[i]>nums[i-1]||!wiggle[j]&&nums[i]<nums[i-1]){
                        len[j]++;
                        wiggle[j]=!wiggle[j];
                    }
                }
            }
            return max(len[0],len[1]);
        }
    

Log in to reply
 

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