```
int wiggleMaxLength(vector<int>& nums) {
if(nums.size()<=1)return nums.size();
int result = 1, increase = 0;
for(int i = 1;i<nums.size();i++){
if(increase>=0&&nums[i]<nums[i-1]){
increase = -1;
result++;
}
if(increase<=0&&nums[i]>nums[i-1]){
increase = 1;
result++;
}
}
return result;
}
```