Share my python binary search solution


  • 0
    D

    standard binary search

    class Solution(object):
        def firstBadVersion(self, n):
            """
            :type n: int
            :rtype: int
            """
            low, high = 1, n
            while low <= high:
                middle = (low + high) >> 1
                if isBadVersion(middle):
                    high = middle - 1
                else:
                    low = middle + 1
    
            return high + 1

Log in to reply
 

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