class Solution:
    def wiggleMaxLength(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        n=len(nums)
        if n==0:
            return 0
        up,down=[0 for i in range(n)],[0 for i in range(n)]
        down[0]=up[0]=1
        for i in range(1,n,1):
            #up
            if nums[i]>nums[i-1]:
                up[i]=down[i-1]+1
                down[i]=down[i-1]
            #down
            elif nums[i]<nums[i-1]:
                down[i]=up[i-1]+1
                up[i]=up[i-1]
            else:
                down[i]=down[i-1]
                up[i]=up[i-1]
        return max(up[n-1],down[n-1])
s=Solution()
print(s.wiggleMaxLength([1,17,5,10,13,15,10,5,16,8]))