1 class Solution { 2 public int wiggleMaxLength(int[] nums) { 3 int up = 1, down = 1; 4 if(nums.length == 0) return 0; 5 for(int i = 0; i < nums.length - 1; i++){ 6 if(nums[i + 1] > nums[i]){ 7 down = up + 1; 8 }else if(nums[i + 1] < nums[i]){ 9 up = down + 1;//注意等于的情况不算 10 } 11 } 12 return Math.max(up, down); 13 } 14 }
动态规划 很懒 拿电脑画图忽悠了 大佬思路牛逼