Description
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit, and return it. This is also known as the digital root of the number. Can you solve it without using loops?
Examples
Input:
num = 38Output:
2Explanation:
3 + 8 = 11, 1 + 1 = 2.
Input:
num = 0Output:
0Explanation:
The digital root of 0 is 0.
Input:
num = 199Output:
1Explanation:
1 + 9 + 9 = 19, then 1 + 9 = 10, then 1 + 0 = 1.
Constraints
- •
0 ≤ num ≤ 2³¹ - 1