classSolution:defwiggleMaxLength(self,nums: List[int]) ->int: iflen(nums)<2:returnlen(nums) pre =0 res =1for i inrange(1, len(nums)): diff = nums[i]- nums[i-1]if pre * diff <=0and diff !=0: res +=1 pre = diffreturn res
classSolution:defwiggleSort(self,nums: List[int]) ->None:# 1. If i is even, then nums[i] <= nums[i - 1].# 2. If i is odd, then nums[i] >= nums[i - 1].for i inrange(1, len(nums)):if i &1==0and nums[i]> nums[i -1]or i &1==1and nums[i]< nums[i -1]: nums[i], nums[i -1]= nums[i -1], nums[i]