Skip to content

Commit e94b592

Browse files
authored
Update 376-wiggle-subsequence.js
1 parent 353ee2a commit e94b592

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

376-wiggle-subsequence.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,24 @@ const wiggleMaxLength = function(nums) {
1515
}
1616
return count
1717
}
18+
19+
// another
20+
21+
/**
22+
* @param {number[]} nums
23+
* @return {number}
24+
*/
25+
const wiggleMaxLength = function(nums) {
26+
const len = nums.length
27+
if (len === 0) return 0
28+
let up = 1
29+
let down = 1
30+
for (let i = 1; i < len; i++) {
31+
if (nums[i] > nums[i - 1]) {
32+
up = down + 1
33+
} else if (nums[i] < nums[i - 1]) {
34+
down = up + 1
35+
}
36+
}
37+
return Math.max(up, down)
38+
}

0 commit comments

Comments
 (0)