My Ruby Solution for first bad version

  • 0
    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)

    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.