增加 0376.摆动序列 go版本

增加 0376.摆动序列 go版本
This commit is contained in:
X-shuffle
2021-07-23 10:55:16 +08:00
committed by GitHub
parent 77aba1c5a4
commit 1176b756a9

View File

@ -151,7 +151,24 @@ class Solution:
``` ```
Go Go
```golang
func wiggleMaxLength(nums []int) int {
var count,preDiff,curDiff int
count=1
if len(nums)<2{
return count
}
for i:=0;i<len(nums)-1;i++{
curDiff=nums[i+1]-nums[i]
//如果有正有负则更新下标值||或者只有前一个元素为0针对两个不等元素的序列也视作摆动序列且摆动长度为2
if (curDiff > 0 && preDiff <= 0) || (preDiff >= 0 && curDiff < 0){
preDiff=curDiff
count++
}
}
return count
}
```
Javascript: Javascript:
```Javascript ```Javascript