Skip to content

Commit 1e681a3

Browse files
committed
Time: 40 ms (39.12%), Space: 17.9 MB (28.85%) - LeetHub
1 parent da11fad commit 1e681a3

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# The guess API is already defined for you.
2+
# @param num, your guess
3+
# @return -1 if num is higher than the picked number
4+
# 1 if num is lower than the picked number
5+
# otherwise return 0
6+
7+
class Solution:
8+
def guessNumber(self, n: int) -> int:
9+
low, high = 1, n
10+
mid = (low + high) // 2
11+
while guess(mid) != 0:
12+
if guess(mid) == -1:
13+
high = mid
14+
elif guess(mid) == 1:
15+
low = mid + 1
16+
mid = (low + high) // 2
17+
return mid

0 commit comments

Comments
 (0)