Short and clear python solution


  • 0
    M
        def guessNumber(self, n):
            low, high = 1, n
            while low <= high:
                num = (low + high) // 2
                if guess(num) == -1:
                    high = num - 1
                elif guess(num) == 1:
                    low = num + 1
                else:
                    return num
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.