Digital Root
Repeatedly replace num with the sum of its decimal digits until only one digit is left, then return that digit.
For example, 38 becomes 3 + 8 = 11, which becomes 1 + 1 = 2.
Example 1
num 38
returns 2
38 -> 11 -> 2.
Example 2
num 7
returns 7
Already one digit.
Constraints
0 <= num <= 10**9
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Math problems
- Excel Sheet Column NumberBeginner
- Handshake CountBeginner
- Harshad NumberBeginner
- Hex String to DecimalBeginner
- Highest Power of TwoBeginner
- Is PrimeBeginner
- Lattice Points in a CircleBeginner
- Leap YearBeginner