From dd21fc7a11715bccaeb7f6da11a4bec4016ecf6e Mon Sep 17 00:00:00 2001 From: Luo <82520819+Jerry-306@users.noreply.github.com> Date: Sat, 2 Oct 2021 10:29:57 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BA=A0=E6=AD=A3=200376=20=E6=91=86=E5=8A=A8?= =?UTF-8?q?=E5=BA=8F=E5=88=97=20JavaScript=E7=89=88=E6=9C=AC=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=8C=BA=E9=97=B4=E9=94=99=E8=AF=AF=20=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 原代码中 存在 区间超出范围问题, 现给出修改方案 --- problems/0376.摆动序列.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/problems/0376.摆动序列.md b/problems/0376.摆动序列.md index 23348bd0..82b67451 100644 --- a/problems/0376.摆动序列.md +++ b/problems/0376.摆动序列.md @@ -177,7 +177,7 @@ var wiggleMaxLength = function(nums) { let result = 1 let preDiff = 0 let curDiff = 0 - for(let i = 0; i <= nums.length; i++) { + for(let i = 0; i < nums.length - 1; i++) { curDiff = nums[i + 1] - nums[i] if((curDiff > 0 && preDiff <= 0) || (curDiff < 0 && preDiff >= 0)) { result++