```
public class Solution {
public int wiggleMaxLength(int[] nums) {
if (nums.length == 0 || nums.length == 1) {
return nums.length;
}
int k=0;
int res = 1;
for(int i=0;i<nums.length-1;i++){
int tmp = nums[i] - nums[i+1];
if(k==0){
k=-tmp;
}
if((k<0 && tmp>0) || (k>0 && tmp<0)){
res++;
k=tmp;
}
}
return res;
}
}
```