From ccfdd971b60b8090c5b9e9ad960e9fbe8a79b4a0 Mon Sep 17 00:00:00 2001 From: fusunx <1102654482@qq.com> Date: Wed, 26 May 2021 08:12:44 +0800 Subject: [PATCH] =?UTF-8?q?0376.=E6=91=86=E5=8A=A8=E5=BA=8F=E5=88=97.md=20?= =?UTF-8?q?Javascript?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0376.摆动序列.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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)