Python O(logn) solution beats 98%


  • 1
    D
    class Solution(object):
        def firstBadVersion(self, n):
            """
            :type n: int
            :rtype: int
            """
            
            def binS(start, end):
                mid = (start+end)/2
                
                if(isBadVersion(mid)):
                    
                    if(not(isBadVersion(mid-1)) or mid==1):
                        return mid
                        
                    elif(isBadVersion(mid-1)):
                        end = mid-1
                        return binS(start,end)
                        
                elif(not(isBadVersion(mid))):
                    start = mid+1
                    return binS(start,end)
                    
            return  binS(0,n)

Log in to reply
 

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