添加 0376.摆动序列 python3版本

This commit is contained in:
evanlai
2021-06-02 23:41:29 +08:00
parent 41c4f17833
commit a748e2ff96

View File

@ -138,7 +138,21 @@ class Solution {
```
Python
```python
class Solution:
def wiggleMaxLength(self, nums: List[int]) -> int:
#贪心 求波峰数量 + 波谷数量
if len(nums)<=1:
return len(nums)
cur, pre = 0,0 #当前一对差值,前一对差值
count = 1#默认最右边有一个峰值
for i in range(len(nums)-1):
cur = nums[i+1] - nums[i]
if((cur>0 and pre<=0) or (cur<0 and pre>=0)):
count += 1
pre = cur
return count
```
Go