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 = 38
Output:2
Explanation:

3 + 8 = 11, 1 + 1 = 2.

Input:num = 0
Output:0
Explanation:

The digital root of 0 is 0.

Input:num = 199
Output:1
Explanation:

1 + 9 + 9 = 19, then 1 + 9 = 10, then 1 + 0 = 1.

Constraints

  • 0 ≤ num ≤ 2³¹ - 1

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!