Clean binary search solution in python


  • 0
    class Solution(object):
        def guessNumber(self, n):
            low, high, = 1, n
            while low <= high:
                mid = low + high >> 1
                judge = guess(mid)
    
                if judge == 0:
                    return mid
    
                if judge < 0:
                    high = mid - 1
                else:
                    low = mid + 1
    

Log in to reply
 

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