Easy understand Solution in python


  • 0
    L

    Not too much to say, just go with binary search:)

    def guessNumber(self, n):
            """
            :type n: int
            :rtype: int
            """
            s, e = 1, n
            while s < e:
                mid = (s + e) / 2
                ret = guess(mid)
                if ret == 0:
                    return mid
                if ret == -1:
                    e = mid - 1
                if ret == 1:
                    s = mid + 1
            return s
    

    very straightforward code.


Log in to reply
 

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