public class Solution {

public int wiggleMaxLength(int[] nums) {

if(nums.length < 2) return nums.length;

int diff=0,count =1;

for(int i=0;i<nums.length-1;i++){

if(diff==0){

diff = nums[i]-nums[i+1];

if(diff != 0) count++;

}else if(diff*(nums[i]-nums[i+1]) < 0) {

count++;

diff = nums[i]-nums[i+1];

}

}

return count;

}

}