标签:ram code other http param src inf obj div
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))
标签:ram code other http param src inf obj div
原文地址:https://www.cnblogs.com/panweiwei/p/12748605.html