We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2552afe commit b90bae6Copy full SHA for b90bae6
guess_number_game.py
@@ -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