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)/有效的山脉数组 [valid-mountain-array].html

49 lines
1.3 KiB
HTML
Raw Normal View History

2022-03-27 20:46:41 +08:00
<p>给定一个整数数组 <code>arr</code>,如果它是有效的山脉数组就返回&nbsp;<code>true</code>,否则返回 <code>false</code></p>
<p>让我们回顾一下,如果 <code>arr</code>&nbsp;满足下述条件,那么它是一个山脉数组:</p>
<ul>
<li><code>arr.length &gt;= 3</code></li>
<li>&nbsp;<code>0 &lt; i&nbsp;&lt; arr.length - 1</code>&nbsp;条件下,存在&nbsp;<code>i</code>&nbsp;使得:
<ul>
<li><code>arr[0] &lt; arr[1] &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>&nbsp;</p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2019/10/20/hint_valid_mountain_array.png" style="height: 316px; width: 500px;" /></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>arr = [2,1]
<strong>输出:</strong>false
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>arr = [3,5,5]
<strong>输出:</strong>false
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>arr = [0,3,2,1]
<strong>输出:</strong>true</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>