36ms python solution


  • 0
    S

    Not the shortest, but easy to understand.

    class Solution(object):
    def firstBadVersion(self, n):
        """
        :type n: int
        :rtype: int
        """
        ### range [l,n]
        l = 1
        r = n
        mid = 0
        while l < r:
            mid = (l + r) / 2
            if isBadVersion(mid): r = mid
            else: l = mid + 1
        ### left one in range
        return r

Log in to reply
 

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