mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 03:33:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			23 lines
		
	
	
		
			796 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			23 lines
		
	
	
		
			796 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
<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 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 <= nums.length <= 1000000</code></li>
 | 
						|
	<li>This problem is the follow-up of the original problem in the book, i.e. the values are not distinct.</li>
 | 
						|
</ol>
 |