Skip to content

Commit b90bae6

Browse files
authored
Create guess_number_game.py
1 parent 2552afe commit b90bae6

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

guess_number_game.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# coding: utf-8
2+
3+
class Solution:
4+
# @param {int} n an integer
5+
# @return {int} the number you guess
6+
def guessNumber(self, n):
7+
# Write your code here
8+
start, end = 1, n
9+
while True:
10+
val = int((start + end) / 2)
11+
r = Guess.guess(val)
12+
if r == 0:
13+
return val
14+
if r < 0: # 期望数字比你猜得小
15+
end = val - 1
16+
else:
17+
start = val + 1
18+
19+
# easy: http://lintcode.com/zh-cn/problem/guess-number-game/

0 commit comments

Comments
 (0)