O(logN) Python solution


  • 0
    L
    class Solution(object):
        def firstBadVersion(self, n):
            """
            :type n: int
            :rtype: int
            """
            start = 1
            end = n
            while start <= end:
                mid = (start + end) / 2
                if isBadVersion(mid):
                    end = mid-1
                    if not isBadVersion(mid-1):
                        return mid
                else:
                    start = mid+1
    

Log in to reply
 

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