文章作者:Tyan 博客:noahsnail.com | CSDN | 简书
1. Description
2. Solution
解析:二分查找问题。
代码语言:javascript复制class Solution:
def guessNumber(self, n):
left = 1
right = n
while left <= right:
mid = (left right) // 2
result = guess(mid)
if result > 0:
left = mid 1
elif result < 0:
right = mid - 1
else:
return mid
Reference
- https://leetcode.com/problems/guess-number-higher-or-lower/