Guess Number Higher or Lower

Solution Code
class Solution:
    def guessNumber(self, n: int) -> int:
        low, high = 1, n
        while low <= high:
            mid = low + (high - low) // 2
            res = guess(mid)
            if res == 0:
                return mid
            elif res < 0:
                high = mid - 1
            else:
                low = mid + 1
Video GuideLeetcode Daily

Time Complexity

O(log n)

Space Complexity

O(1)