Skip to content

Commit 6d2549d

Browse files
committed
Time: 41 ms (29.19%), Space: 17.6 MB (93.39%) - LeetHub
1 parent 40e4933 commit 6d2549d

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed
Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
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-
71
class Solution:
82
def guessNumber(self, n: int) -> int:
93
low, high = 1, n
10-
mid = (low + high) // 2
11-
while guess(mid) != 0:
12-
if guess(mid) == -1:
4+
5+
while low <= high:
6+
mid = (low + high) // 2
7+
A = guess(mid)
8+
if A == -1:
139
high = mid
14-
elif guess(mid) == 1:
10+
elif A == 1:
1511
low = mid + 1
16-
mid = (low + high) // 2
17-
return mid
12+
else:
13+
return mid

0 commit comments

Comments
 (0)