Simple binary search with Python beats 99.91% submissions


  • 0
    K

    0_1472897387063_upload-76ee2660-7389-4c5a-84c2-d049dc4eab00

    class Solution(object):
    def guessNumber(self, n):
        """
        :type n: int
        :rtype: int
        """
        begin = 1
        end = n
        while 1:
            mid = (begin + end) / 2
            g = guess(mid)
            if g == 0:
                return mid
            if g == -1:
                end = mid - 1
            if g == 1:
                begin = mid + 1
            mid = (begin + end) / 2
            g = guess(mid)
        return mid

  • 0
    M

    remove this
    mid = (begin + end) / 2
    g = guess(mid)


Log in to reply
 

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