2
* @param {number[]} nums5
var wiggleMaxLength = function (nums) {7
//assume we start with positive or start with negative8
//choose the longest of the two9
return Math.max(helper(nums, true), helper(nums, false));12
const helper = (nums, start) => {15
let res = nums.length;17
while (r < nums.length) {18
//if sign are what we expected, just flip the sign19
if ((sign && nums[r] > nums[l]) || (!sign && nums[r] < nums[l])) {22
//if sign aren't what we expected then we "remove" one23
//if we want positive then we remove the bigger number to give us a better chance of getting positive24
//if we want negative we remove the smaller number go give us a chance of getting a negative25
// want negative but nums[r] - nums[l] = positive => remove nums[l]26
// want positive but nums[r] - nums[l] = negative => remove nums[l]27
//it just so happens that the number we want to remove will always be nums[l], so we don't have to do anything special