mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 11:43:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			46 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			46 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>We are playing the Guess Game. The game is as follows:</p>
 | 
						|
 | 
						|
<p>I pick a number from <code>1</code> to <code>n</code>. You have to guess which number I picked.</p>
 | 
						|
 | 
						|
<p>Every time you guess wrong, I will tell you whether the number I picked is higher or lower than your guess.</p>
 | 
						|
 | 
						|
<p>You call a pre-defined API <code>int guess(int num)</code>, which returns three possible results:</p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li><code>-1</code>: Your guess is higher than the number I picked (i.e. <code>num > pick</code>).</li>
 | 
						|
	<li><code>1</code>: Your guess is lower than the number I picked (i.e. <code>num < pick</code>).</li>
 | 
						|
	<li><code>0</code>: your guess is equal to the number I picked (i.e. <code>num == pick</code>).</li>
 | 
						|
</ul>
 | 
						|
 | 
						|
<p>Return <em>the number that I picked</em>.</p>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong class="example">Example 1:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> n = 10, pick = 6
 | 
						|
<strong>Output:</strong> 6
 | 
						|
</pre>
 | 
						|
 | 
						|
<p><strong class="example">Example 2:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> n = 1, pick = 1
 | 
						|
<strong>Output:</strong> 1
 | 
						|
</pre>
 | 
						|
 | 
						|
<p><strong class="example">Example 3:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> n = 2, pick = 1
 | 
						|
<strong>Output:</strong> 1
 | 
						|
</pre>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<p><strong>Constraints:</strong></p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li><code>1 <= n <= 2<sup>31</sup> - 1</code></li>
 | 
						|
	<li><code>1 <= pick <= n</code></li>
 | 
						|
</ul>
 |