You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<h2><ahref="https://leetcode.com/problems/guess-number-higher-or-lower">374. Guess Number Higher or Lower</a></h2><h3>Easy</h3><hr><p>We are playing the Guess Game. The game is as follows:</p>
2
+
3
+
<p>I pick a number from <code>1</code> to <code>n</code>. You have to guess which number I picked.</p>
4
+
5
+
<p>Every time you guess wrong, I will tell you whether the number I picked is higher or lower than your guess.</p>
6
+
7
+
<p>You call a pre-defined API <code>int guess(int num)</code>, which returns three possible results:</p>
8
+
9
+
<ul>
10
+
<li><code>-1</code>: Your guess is higher than the number I picked (i.e. <code>num > pick</code>).</li>
11
+
<li><code>1</code>: Your guess is lower than the number I picked (i.e. <code>num < pick</code>).</li>
12
+
<li><code>0</code>: your guess is equal to the number I picked (i.e. <code>num == pick</code>).</li>
13
+
</ul>
14
+
15
+
<p>Return <em>the number that I picked</em>.</p>
16
+
17
+
<p> </p>
18
+
<p><strongclass="example">Example 1:</strong></p>
19
+
20
+
<pre>
21
+
<strong>Input:</strong> n = 10, pick = 6
22
+
<strong>Output:</strong> 6
23
+
</pre>
24
+
25
+
<p><strongclass="example">Example 2:</strong></p>
26
+
27
+
<pre>
28
+
<strong>Input:</strong> n = 1, pick = 1
29
+
<strong>Output:</strong> 1
30
+
</pre>
31
+
32
+
<p><strongclass="example">Example 3:</strong></p>
33
+
34
+
<pre>
35
+
<strong>Input:</strong> n = 2, pick = 1
36
+
<strong>Output:</strong> 1
37
+
</pre>
38
+
39
+
<p> </p>
40
+
<p><strong>Constraints:</strong></p>
41
+
42
+
<ul>
43
+
<li><code>1 <= n <= 2<sup>31</sup> - 1</code></li>
0 commit comments