How to find the longest turbulent subarray by leetcode
Editor to share with you how to find the longest turbulence sub-array of leetcode, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
When the subarray A [I], A [ionization 1],..., A [j] of A satisfies the following conditions, we call it a turbulent subarray:
If I A [ku 1], and when 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:
Enter: [100]
Output: 1
Tip:
one