标签:bsp 序列 mamicode code div sequence leetcode color question
数组长度:
1.长度<=1时:
返回值:数组长度
2.长度>1时:
up,down交替记录摆动情况(初始值=1)
(1)当num[i]-num[i+1]>0时(下降趋势)
down = up + 1;
(2)当num[i]-num[i+1]<0时(上升趋势)
up = down + 1;
返回值 max(up,down)
public int wiggleMaxLength(int[] nums) { if (nums.length <= 1) return nums.length; else { int up=1; int down=1; for(int i=0;i<nums.length-1;++i){ if(nums[i]-nums[i+1]<0){ down = up+1; } else if(nums[i]-nums[i+1]>0){ up = down+1; } } return up>down?up:down; } }
标签:bsp 序列 mamicode code div sequence leetcode color question
原文地址:https://www.cnblogs.com/ANullValue/p/14124993.html