Leetcode 374. Guess Number Higher or Lower | | Leetcode 374. Guess Number Higher or Lower 文章作者:Tyan博客:noahsnail.com | CSDN | 简书 1. Description 2. Solution解析:二分查找问题。 12345678910111213class 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/ 如果有收获,可以请我喝杯咖啡! 赏 微信打赏 支付宝打赏