```
public int wiggleMaxLength(int[] nums) {
if(nums.length <= 1) return nums.length;
int count = 1;
for(int i = 1, diff = 0; i < nums.length; i++){
int curDiff = nums[i] - nums[i - 1];
if(diff == 0 && curDiff != 0 || curDiff != 0 && (curDiff ^ diff) < 0){
count++;
diff = curDiff;
}
}
return count;
}
```