// https://leetcode.com/problems/guess-number-higher-or-lower

# The guess API is already defined for you.
# @param num, your guess
# @return -1 if my number is lower, 1 if my number is higher, otherwise return 0
# def guess(num: int) -> int:

class Solution:
    def guessNumber(self, n: int) -> int:
        left = 1
        right = 2**31 - 1
        
        while ( left <= right ):
            pivot = left + (right-left)//2
            num = guess(pivot)
            if num < 0:
                right = pivot - 1
            elif num > 0:
                left = pivot + 1
            else:
                return pivot
        