Python iterative solution


  • 0
    class Solution(object):
        def guessNumber(self, n):
            l = 1; r = n
            while l < r:
                m = (l+r)/2
                myguess = guess(m)
                if myguess == 0: return m
                elif myguess > 0: l = m+1
                else: r = m-1
            return l
    

Log in to reply
 

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