Vanilla Binary Search Python


  • 0
    class Solution(object):
        def guessNumber(self, n):
            left, right = 1, n
            while left < right:
                status = guess((left + right) >> 1)
                left, right = left if status != 1 else ((left + right) >> 1) + 1, right if status  == 1 else (left + right) >> 1
            return left
    

Log in to reply
 

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