纠正 0376 摆动序列 JavaScript版本代码区间错误 问题

原代码中 存在 区间超出范围问题, 现给出修改方案
This commit is contained in:
Luo 2021-10-02 10:29:57 +08:00 committed by GitHub
parent 18a9fe0f07
commit dd21fc7a11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 1 deletions

View File

@ -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++