1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/数组中的最长山脉 [longest-mountain-in-array].html
2022-03-29 12:43:11 +08:00

50 lines
1.3 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>把符合下列属性的数组 <code>arr</code> 称为 <strong>山脉数组</strong> </p>
<ul>
<li><code>arr.length &gt;= 3</code></li>
<li>存在下标 <code>i</code><code>0 &lt; i &lt; arr.length - 1</code>),满足
<ul>
<li><code>arr[0] &lt; arr[1] &lt; ... &lt; arr[i - 1] &lt; arr[i]</code></li>
<li><code>arr[i] &gt; arr[i + 1] &gt; ... &gt; arr[arr.length - 1]</code></li>
</ul>
</li>
</ul>
<p>给出一个整数数组 <code>arr</code>,返回最长山脉子数组的长度。如果不存在山脉子数组,返回 <code>0</code></p>
<p>&nbsp;</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>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= arr.length &lt;= 10<sup>4</sup></code></li>
<li><code>0 &lt;= arr[i] &lt;= 10<sup>4</sup></code></li>
</ul>
<p>&nbsp;</p>
<p><strong>进阶:</strong></p>
<ul>
<li>你可以仅用一趟扫描解决此问题吗?</li>
<li>你可以用 <code>O(1)</code> 空间解决此问题吗?</li>
</ul>