```
public class Solution {
public int wiggleMaxLength(int[] nums) {
if(nums == null) return 0;
if(nums.length <= 1) return nums.length;
int n1 = nums[0], n2 = n1;
int res = 1;
for(int n : nums){
if((n1 == n2 && n != n2) || (n > n2 && n2 < n1) || (n < n2 && n2 > n1)){
res++;
n1 = n2;
}
n2 = n;
}
return res;
}
}
```