WiggleSubsequence { public int wiggleMaxLength(int[] nums) { if (nums.length == 0) return 0; int i = 0; while (i + 1 < nums.length && nums[i] == nums[i + 1]) { i++; } int wiggle = 1; int up = 0; while (i + 1 < nums.length) { if (up == 0) { up = nums[i] < nums[i + 1] ? 1 : 2; wiggle++; } else if (up == 1) { if (nums[i] > nums[i + 1]) { wiggle++; up = 2; } } else { if (nums[i] < nums[i + 1]) { wiggle++; up = 1; } } i++; } return wiggle; }  int wiggleMaxLength(int[] nums);  }
@Test(dataProvider = "wiggleArray") public void test(int[] wiggles, int len) { assertEquals(new WiggleSubsequence().wiggleMaxLength(wiggles), len); }