```
int wiggleMaxLength(vector<int>& nums) {
int flag = 0,m = nums.size(),res = 1,temp;
if(m == 0) return 0;
for(int i = 1;i != m;++i){
if(flag == 0)
flag = (nums[i-1] - nums[i]);
temp = flag *(nums[i] - nums[i-1]);
flag = temp >= 0?flag:0-flag;
res = temp >= 0?res:res+1;
}
return res;
}
```