My Ruby Solution for first bad version


  • 0
    S
    def first_bad_version(n, p=0)
        return n if n == p
        t = (p+n)/2
        is_bad_version(t) ? first_bad_version(t, p) : first_bad_version(n, t + 1)
    end
    

    recursion solution. it works, and very fast, :)


Log in to reply
 

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