1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-10-18 19:46:47 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
2022-03-29 12:43:11 +08:00
parent 58bbdfd57c
commit 2b0511d272
10721 changed files with 8123 additions and 8119 deletions

View File

@@ -0,0 +1,35 @@
<p>峰值元素是指其值严格大于左右相邻值的元素。</p>
<p>给你一个整数数组&nbsp;<code>nums</code>,找到峰值元素并返回其索引。数组可能包含多个峰值,在这种情况下,返回 <strong>任何一个峰值</strong> 所在位置即可。</p>
<p>你可以假设&nbsp;<code>nums[-1] = nums[n] = -∞</code></p>
<p>你必须实现时间复杂度为 <code>O(log n)</code><em> </em>的算法来解决此问题。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>nums = <code>[1,2,3,1]</code>
<strong>输出:</strong>2
<strong>解释:</strong>3 是峰值元素,你的函数应该返回其索引 2。</pre>
<p><strong>示例&nbsp;2</strong></p>
<pre>
<strong>输入:</strong>nums = <code>[</code>1,2,1,3,5,6,4]
<strong>输出:</strong>1 或 5
<strong>解释:</strong>你的函数可以返回索引 1其峰值元素为 2
&nbsp; 或者返回索引 5 其峰值元素为 6。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 1000</code></li>
<li><code>-2<sup>31</sup> &lt;= nums[i] &lt;= 2<sup>31</sup> - 1</code></li>
<li>对于所有有效的 <code>i</code> 都有 <code>nums[i] != nums[i + 1]</code></li>
</ul>