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 (English)/魔术索引(English) [magic-index-lcci].html

23 lines
818 B
HTML
Raw Normal View History

<p>A magic index in an array <code>A[0...n-1]</code> is defined to be an index such that <code>A[i] = i</code>. Given a sorted array of&nbsp;integers, write a method to find a magic index, if one exists, in array A. If not, return -1. If there are more than one magic index, return the smallest one.</p>
<p><strong>Example1:</strong></p>
<pre>
<strong> Input</strong>: nums = [0, 2, 3, 4, 5]
<strong> Output</strong>: 0
</pre>
<p><strong>Example2:</strong></p>
<pre>
<strong> Input</strong>: nums = [1, 1, 1]
<strong> Output</strong>: 1
</pre>
<p><strong>Note:</strong></p>
<ol>
<li><code>1 &lt;= nums.length &lt;= 1000000</code></li>
<li>This problem is the&nbsp;follow-up of the original problem in the book, i.e.&nbsp;the values are&nbsp;not distinct.</li>
</ol>