We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 40e4933 commit 6d2549dCopy full SHA for 6d2549d
0374-guess-number-higher-or-lower/0374-guess-number-higher-or-lower.py
@@ -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
-
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:
+
+ while low <= high:
+ mid = (low + high) // 2
+ A = guess(mid)
+ if A == -1:
13
high = mid
14
- elif guess(mid) == 1:
+ elif A == 1:
15
low = mid + 1
16
17
- return mid
+ else:
+ return mid
0 commit comments