0376.摆动序列.md Javascript
This commit is contained in:
parent
fe0abe75fd
commit
ccfdd971b6
|
|
@ -143,7 +143,23 @@ Python:
|
||||||
Go:
|
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)
|
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue