1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/最长湍流子数组 [longest-turbulent-subarray].html

54 lines
1.7 KiB
HTML
Raw Normal View History

2022-03-27 20:46:41 +08:00
<p>给定一个整数数组 <code>arr</code>&nbsp;,返回 <code>arr</code>&nbsp;&nbsp;<em>最大湍流子数组的<strong>长度</strong></em><strong>&nbsp;</strong></p>
<p>如果比较符号在子数组中的每个相邻元素对之间翻转,则该子数组是&nbsp;<strong>湍流子数组</strong>&nbsp;</p>
<p>更正式地来说,当 <code>arr</code>&nbsp;的子数组&nbsp;<code>A[i], A[i+1], ..., A[j]</code>&nbsp;满足仅满足下列条件时,我们称其为<em>湍流子数组</em></p>
<ul>
<li>&nbsp;<code>i &lt;= k &lt; j</code>&nbsp;
<ul>
<li><code>k</code>&nbsp;为奇数时,&nbsp;<code>A[k] &gt; A[k+1]</code>,且</li>
<li><code>k</code> 为偶数时,<code>A[k] &lt; A[k+1]</code></li>
</ul>
</li>
<li><strong></strong>&nbsp;<code>i &lt;= k &lt; j</code>&nbsp;
<ul>
<li><code>k</code> 为偶数时,<code>A[k] &gt; A[k+1]</code>&nbsp;,且</li>
<li><code>k</code>&nbsp;为奇数时,&nbsp;<code>A[k] &lt; A[k+1]</code></li>
</ul>
</li>
</ul>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>arr = [9,4,2,10,7,8,8,1,9]
<strong>输出:</strong>5
<strong>解释:</strong>arr[1] &gt; arr[2] &lt; arr[3] &gt; arr[4] &lt; arr[5]</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>arr = [4,8,12,16]
<strong>输出:</strong>2
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>arr = [100]
<strong>输出:</strong>1
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= arr.length &lt;= 4 * 10<sup>4</sup></code></li>
<li><code>0 &lt;= arr[i] &lt;= 10<sup>9</sup></code></li>
</ul>