mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
50 lines
1.3 KiB
HTML
50 lines
1.3 KiB
HTML
<p>把符合下列属性的数组 <code>arr</code> 称为 <strong>山脉数组</strong> :</p>
|
||
|
||
<ul>
|
||
<li><code>arr.length >= 3</code></li>
|
||
<li>存在下标 <code>i</code>(<code>0 < i < arr.length - 1</code>),满足
|
||
<ul>
|
||
<li><code>arr[0] < arr[1] < ... < arr[i - 1] < arr[i]</code></li>
|
||
<li><code>arr[i] > arr[i + 1] > ... > arr[arr.length - 1]</code></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
<p>给出一个整数数组 <code>arr</code>,返回最长山脉子数组的长度。如果不存在山脉子数组,返回 <code>0</code> 。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>示例 1:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>arr = [2,1,4,7,3,2,5]
|
||
<strong>输出:</strong>5
|
||
<strong>解释:</strong>最长的山脉子数组是 [1,4,7,3,2],长度为 5。
|
||
</pre>
|
||
|
||
<p><strong>示例 2:</strong></p>
|
||
|
||
<pre>
|
||
<strong>输入:</strong>arr = [2,2,2]
|
||
<strong>输出:</strong>0
|
||
<strong>解释:</strong>不存在山脉子数组。
|
||
</pre>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>1 <= arr.length <= 10<sup>4</sup></code></li>
|
||
<li><code>0 <= arr[i] <= 10<sup>4</sup></code></li>
|
||
</ul>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>进阶:</strong></p>
|
||
|
||
<ul>
|
||
<li>你可以仅用一趟扫描解决此问题吗?</li>
|
||
<li>你可以用 <code>O(1)</code> 空间解决此问题吗?</li>
|
||
</ul>
|