Find the Digital Root

Given a non-negative integer n, repeatedly replace it with the sum of its decimal digits until only one digit remains. Return that final digit, called the…

Given a non-negative integer `n`, repeatedly replace it with the sum of its decimal digits until only one digit remains. Return that final digit, called the digital root of `n`. The digital root of `0` is `0`.

- `0 <= n <= 10^9` - `n` is always an integer.

Example 1: input n = 493193; output 2. The reductions are 4 + 9 + 3 + 1 + 9 + 3 = 29, then 2 + 9 = 11, then 1 + 1 = 2.

Example 2: input n = 99999; output 9. The reductions are 9 + 9 + 9 + 9 + 9 = 45, then 4 + 5 = 9.

Example 3: input n = 0; output 0. Zero is already a single digit, so its digital root is zero.

Category: Math. Topic: math. Difficulty: Easy. Patterns: math.