My Python Solution


  • 0
    M
    def guessNumber(self, n):
            head = 1
            tail = n
            cursor = max(n >> 1, head)
    
            while True:
                score = guess(cursor)
                if score == 1:
                    head = max(cursor, head + 1)
                    cursor = (tail + head) >> 1
                elif score == -1:
                    tail = min(cursor, tail - 1)
                    cursor = (tail + head) >> 1
                else:
                    return cursor
    

Log in to reply
 

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