Add Digits

Easy

Repeatedly add all the digits of num until a single digit remains, and return it.

Example 1

addDigits()
Input
num = 38
Output
2

Why

3 + 8 = 11 → 1 + 1 = 2

Example 2

addDigits()
Input
num = 0
Output
0
Constraints
0 <= num <= 2^31 - 1

Topics

MathSimulationNumber Theory

Implement addDigits in the editor and return the answer — printing it is never graded.