1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-27 02:30:28 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/山脉数组的峰顶索引 [peak-index-in-a-mountain-array].html

48 lines
1.3 KiB
HTML
Raw Normal View History

2022-03-27 20:46:41 +08:00
符合下列属性的数组 <code>arr</code> 称为 <strong>山脉数组</strong>
<ul>
2023-12-09 18:42:21 +08:00
<li><code>arr.length &gt;= 3</code></li>
<li>存在 <code>i</code><code>0 &lt; i&nbsp;&lt; arr.length - 1</code>)使得:
2022-03-27 20:46:41 +08:00
<ul>
2023-12-09 18:42:21 +08:00
<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>
2022-03-27 20:46:41 +08:00
</ul>
</li>
</ul>
2023-12-09 18:42:21 +08:00
<p>给你由整数组成的山脉数组 <code>arr</code> ,返回满足 <code>arr[0] &lt; arr[1] &lt; ... arr[i - 1] &lt; arr[i] &gt; arr[i + 1] &gt; ... &gt; arr[arr.length - 1]</code> 的下标 <code>i</code></p>
2022-03-27 20:46:41 +08:00
2023-12-09 18:42:21 +08:00
<p>你必须设计并实现时间复杂度为 <code>O(log(n))</code> 的解决方案。</p>
<p>&nbsp;</p>
2022-03-27 20:46:41 +08:00
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>arr = [0,1,0]
<strong>输出:</strong>1
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>arr = [0,2,1,0]
<strong>输出:</strong>1
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>arr = [0,10,5,2]
<strong>输出:</strong>1
</pre>
2023-12-09 18:42:21 +08:00
<p>&nbsp;</p>
2022-03-27 20:46:41 +08:00
<p><strong>提示:</strong></p>
<ul>
2023-12-09 18:42:21 +08:00
<li><code>3 &lt;= arr.length &lt;= 10<sup>5</sup></code></li>
<li><code>0 &lt;= arr[i] &lt;= 10<sup>6</sup></code></li>
2022-03-27 20:46:41 +08:00
<li>题目数据保证 <code>arr</code> 是一个山脉数组</li>
</ul>