```
public int wiggleMaxLength(int[] nums) {
int size = nums.length;
if(size<=1)return size;
int temp = 1,sign = 0,i = 0;
while(i<size-1){
if(nums[i]>nums[i+1] && (sign==-1 || sign == 0)){
sign=1;
temp++;
}
if(nums[i]<nums[i+1] && (sign==1 || sign == 0)){
sign=-1;
temp++;
}
i++;
}
return temp;
}
```