diff --git a/problems/0376.摆动序列.md b/problems/0376.摆动序列.md index db80a3e5..6fa30cde 100644 --- a/problems/0376.摆动序列.md +++ b/problems/0376.摆动序列.md @@ -143,7 +143,23 @@ Python: Go: - +Javascript: +```Javascript +var wiggleMaxLength = function(nums) { + if(nums.length <= 1) return nums.length + let result = 1 + let preDiff = 0 + let curDiff = 0 + for(let i = 0; i <= nums.length; i++) { + curDiff = nums[i + 1] - nums[i] + if((curDiff > 0 && preDiff <= 0) || (curDiff < 0 && preDiff >= 0)) { + result++ + preDiff = curDiff + } + } + return result +}; +``` ----------------------- * 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)