python binary search


  • 0
    Y
        def firstBadVersion(self, n):
            """
            :type n: int
            :rtype: int
            """
            if isBadVersion(1):
                return 1
            l=1
            r=n
            while l<r-1:
                mid=(l+r)//2
                if isBadVersion(mid):
                    r=mid
                else:
                    l=mid
            return r
    

Log in to reply
 

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