```
class Solution(object):
def wiggleMaxLength(self, nums):
n = len(nums)
if n == 0: return 0
m = 0; prevDiff = 0
for i in range(n-1):
diff = nums[i+1] - nums[i]
if diff*prevDiff < 0: m += 1
elif diff != 0 and m == 0: m = 1
if diff != 0: prevDiff = diff
return m+1
```