Class Solution
java.lang.Object
g0301_0400.s0374_guess_number_higher_or_lower.Solution
374 - Guess Number Higher or Lower.<p>Easy</p>
<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 3 possible results:</p>
<ul>
<li><code>-1</code>: The number I picked is lower than your guess (i.e. <code>pick < num</code>).</li>
<li><code>1</code>: The number I picked is higher than your guess (i.e. <code>pick > num</code>).</li>
<li><code>0</code>: The number I picked is equal to your guess (i.e. <code>pick == num</code>).</li>
</ul>
<p>Return <em>the number that I picked</em>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> n = 10, pick = 6</p>
<p><strong>Output:</strong> 6</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> n = 1, pick = 1</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> n = 2, pick = 1</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Example 4:</strong></p>
<p><strong>Input:</strong> n = 2, pick = 2</p>
<p><strong>Output:</strong> 2</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>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
guessNumber
public int guessNumber(int n)
-