This is greedy, not dp.

public int wiggleMaxLength(int[] nums) { int n = nums.length; if(n <= 1) return n; int i = 1; for(; i < n; i++){ if(nums[i] != nums[i - 1]) break; } if(i == n) return 1; boolean isIncreasing = nums[i] > nums[i - 1]; i++; int max = 2; for(; i < n; i++){ if(isIncreasing && nums[i] < nums[i - 1]) { max++; isIncreasing = false; } else if(!isIncreasing && nums[i] > nums[i - 1]){ max++; isIncreasing = true; } } return max; }Wiggle Subsequence