How to realize the longest turbulent subarray by leetcode
This article mainly introduces how to achieve the longest turbulence subarray of leetcode. The introduction in this article is very detailed and has certain reference value. Interested friends must read it!
I. Content of the topic
When A[i], A[i+1],..., A[j] is called a turbulence subarray when it satisfies the following conditions:
If i A[k+1] and k is even, A[k]
< A[k+1]; 或 若 i A[k+1] ,且当 k 为奇数时, A[k] < A[k+1]。 也就是说,如果比较符号在子数组中的每个相邻元素对之间翻转,则该子数组是湍流子数组。 返回 A 的最大湍流子数组的长度。 示例 1: 输入:[9,4,2,10,7,8,8,1,9] 输出:5 解释:(A[1] >A[2]
< A[3] >A[4] < A[5])
Example 2:
Input: [4, 8, 12, 16]
Output: 2
Example 3:
Input: [100]
Output: 1
Tip:
1