Simple recursive Ruby with no mod


  • 0
    T
    def add_digits(num)
        return num if num.to_s.length == 1
        add_digits num.to_s.each_char.reduce(0) { |m, c| m + c.to_i }
    end
    

Log in to reply
 

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