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)/魔术索引 [magic-index-lcci].html
2022-03-29 12:43:11 +08:00

22 lines
811 B
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>A[0...n-1]</code>中,有所谓的魔术索引,满足条件<code>A[i] = i</code>。给定一个有序整数数组编写一种方法找出魔术索引若有的话在数组A中找出一个魔术索引如果没有则返回-1。若有多个魔术索引返回索引值最小的一个。</p>
<p><strong>示例1:</strong></p>
<pre><strong> 输入</strong>nums = [0, 2, 3, 4, 5]
<strong> 输出</strong>0
<strong> 说明</strong>: 0下标的元素为0
</pre>
<p><strong>示例2:</strong></p>
<pre><strong> 输入</strong>nums = [1, 1, 1]
<strong> 输出</strong>1
</pre>
<p><strong>说明:</strong></p>
<ol>
<li>nums长度在[1, 1000000]之间</li>
<li>此题为原书中的 Follow-up即数组中可能包含重复元素的版本</li>
</ol>