Skip to content

Commit 0e30041

Browse files
authored
Merge pull request neetcode-gh#1466 from grievous-mischievous7/patch-1
Create: 374-Guess-Number-Higher-or-Lower.py
2 parents 05c7c18 + 227c1b9 commit 0e30041

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution:
2+
def guessNumber(self, n: int) -> int:
3+
# return a num btw 1,..,n
4+
5+
low = 1
6+
high = n
7+
8+
while True:
9+
mid = low + (high - low) // 2
10+
myGuess = guess(mid)
11+
if myGuess == 1:
12+
low = mid + 1
13+
elif myGuess == -1:
14+
high = mid - 1
15+
else:
16+
return mid

0 commit comments

Comments
 (0)