<jupyter_start><jupyter_text>摆动序列：    1、如果一个数字序列相邻两个数字的差值是正负交替的，则为摆动序列。    2、少于等于两个数字的序列为摆动序列。求：一个序列中满足摆动序列的最大长度例题1:    Input: [1,7,4,9,2,5], 相邻两个数字之间的差为：[6, -3, 5, -7, 3]    Output: 6例题2：    Input: [1,17,5,10,13,15,10,5,16,8] --> [16, -12, 5, 3, 2, -5, -5, 11, -8]    Output: 7    [1,17,10,13,10,16,8] 满足摆动序列的需求例题3：    Input: [1,2,3,4,5,6,7,8,9] --> [1, 1, 1, 1, 1]    Output: [2]<jupyter_code>class Solution:
    def wiggleMaxLength(self, nums) -> int:
        if len(nums) < 2:
            return len(nums)
        
        # 先求起始序列的正负号
        satisfied_list = []
        index = 0
        next_index = index + 1
        while next_index < len(nums):
            if nums[next_index] - nums[index] > 0:
                past_symbol = 'p'
                break
            elif nums[next_index] - nums[index] < 0:
                past_symbol = 'n'
                break
            else:
                if next_index + 1 < len(nums):
                    next_index += 1
                else:
                    return 0 
        
        satisfied_list.extend([nums[index], nums[next_index]])
        index = next_index
        while next_index < len(nums):
            print(next_index, index)
            if nums[next_index] - nums[index] > 0:
                current_symbol = 'p'
            elif nums[next_index] - nums[index] < 0:
                current_symbol = 'n'
            else:
                next_index += 1
                continue   
                
            if current_symbol != past_symbol:
                satisfied_list.append(nums[next_index])
                past_symbol = current_symbol
                index = next_index
                next_index = index + 1
            else:
                next_index += 1
        print(satisfied_list)
        return len(satisfied_list)
solution = Solution()
solution.wiggleMaxLength([1,17,5,10,13,15,10,5,16,8])<jupyter_output>1 1
2 1
3 2
4 3
5 3
6 3
7 3
8 7
9 8
[1, 17, 5, 10, 5, 16, 8]<jupyter_text>[1,17,5,10,13,15,10,5,16,8] = step 1:    up = 1, down = 1step 2:    index = 1, nums[index] = 17, nums[index-1]=1, 17-1>0, up = down + 1 = 2step 3:    index = 2, nums[index] = 5, nums[index-1] = 17, 5-17<0, down=up+1 = 3<jupyter_code>class Solution:
    def wiggleMaxLength(self, nums) -> int:
        if len(nums) < 2:
            return len(nums)
        
        up, down = 1, 1
        
        for index in range(1, len(nums)):
            if nums[index] - nums[index - 1] > 0:
                up = down + 1
            if nums[index] - nums[index - 1] < 0:
                down = up + 1
        return max(up, down)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13005339435545385, 'fraction_numerical': 0.06979405034324943, 'mean_word_length': 1.6468213925327952, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '275654', 'license': 'Apache-2.0', 'n_tokens_mistral': 1144, 'n_tokens_neox': 1038, 'n_words': 214, 'path': 'Greedy/previous/376. Wiggle Subsequence.ipynb', 'repo_name': 'YuHe0108/Leetcode', 'size': '2622'}