The question want we to get digits root. There is a trick, a digits root of a number is equals to number%9.
def add_digits(num) num==0 ? 0:(num%9==0 ? 9 : num%9) end
Hi, acearth. Could you please explain what you mean by the word "root"? Does what we compute in this problem have a formal name "root"?
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.