Skip to content

Commit ccfdd97

Browse files
committed
0376.摆动序列.md Javascript
1 parent fe0abe7 commit ccfdd97

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

problems/0376.摆动序列.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,23 @@ Python:
143143
Go:
144144

145145

146-
146+
Javascript:
147+
```Javascript
148+
var wiggleMaxLength = function(nums) {
149+
if(nums.length <= 1) return nums.length
150+
let result = 1
151+
let preDiff = 0
152+
let curDiff = 0
153+
for(let i = 0; i <= nums.length; i++) {
154+
curDiff = nums[i + 1] - nums[i]
155+
if((curDiff > 0 && preDiff <= 0) || (curDiff < 0 && preDiff >= 0)) {
156+
result++
157+
preDiff = curDiff
158+
}
159+
}
160+
return result
161+
};
162+
```
147163

148164
-----------------------
149165
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)

0 commit comments

Comments
 (0)