![](https://img2020.cnblogs.com/blog/947397/202004/947397-20200421224850594-298207693.png)
1 # The guess API is already defined for you.
2 # @param num, your guess
3 # @return -1 if my number is lower, 1 if my number is higher, otherwise return 0
4 # def guess(num):
5
6 class Solution(object):
7 def guessNumber(self, n):
8 """
9 :type n: int
10 :rtype: int
11 """
12 i, j = 1, n
13 while i < j:
14 mid = i + int((j - i) / 2)
15 if guess(mid) == -1:
16 j = mid
17 elif guess(mid) == 1:
18 i = mid + 1
19 elif guess(mid) == 0:
20 return mid
21 return i
22
23
24 if __name__ == '__main__':
25 solution = Solution()
26 print(solution.guessNumber(10))