<jupyter_start><jupyter_text>A的子阵A[i]，A[i+1]，…，A[j]称为 turbulent：    1、当且仅当对于 i<= k < j，       当k为奇数：A[k] > A[k+1]，当k为偶数时：A[k] < A[k+1]    2、或者，对于 i<= k < j，       当k为偶数：A[k] > A[k+1]，当k为奇数时：A[k] < A[k+1]    也就是说，如果比较符号在子阵列中每个相邻的元素对之间翻转，子阵列就是湍流的。返回a的最大尺寸湍流子阵的长度。    Example 1:    Input: [9,4,2,10,7,8,8,1,9]    Output: 5    Explanation: (A[1] > A[2]  A[4] < A[5])Example 2:    Input: [4,8,12,16]    Output: 2Example 3:    Input: [100]    Output: 1<jupyter_code>class Solution:
    def maxTurbulenceSize(self, A) -> int:
        size = len(A)
        if size < 2: return 1
        dp = [2] * size
        dp[0] = 1
        flag = 1 if A[1] > A[0] else 0
        for i in range(1, size):
            if A[i] == A[i-1]:
                dp[i] = 1
                continue
            if flag and A[i] < A[i-1]:
                dp[i] = dp[i-1] + 1
                flag = 0
            elif not flag and A[i] > A[i-1]:
                dp[i] = dp[i-1] + 1
                flag = 1
            
        return max(dp)
nums_ = [9,4,2,10,7,8,8,1,9]
solution = Solution()
solution.maxTurbulenceSize(nums_)<jupyter_output>4
2
{'fraction_non_alphanumeric': 0.1735611510791367, 'fraction_numerical': 0.06115107913669065, 'mean_word_length': 1.8685567010309279, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 10, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '212551', 'license': 'Apache-2.0', 'n_tokens_mistral': 578, 'n_tokens_neox': 557, 'n_words': 102, 'path': 'Dynamic Programming/0809/978. Longest Turbulent Subarray.ipynb', 'repo_name': 'YuHe0108/Leetcode', 'size': '1112'}