Problem · Math
Add Digits
Learn this problemProblem statement
Given a non-negative integer num, repeatedly add all of its decimal digits until the result has only one digit.
Return that single-digit result.
Function
addDigits(num: int) → intExamples
Example 1
num = 38return = 2The process is 38 -> 3 + 8 = 11 -> 1 + 1 = 2.
Example 2
num = 0return = 0The input already has one digit, so the result is 0.
Example 3
num = 99999return = 9The digit sum is 45, and 4 + 5 = 9.
Constraints
0 <= num <= 2^31 - 1
More Arcesium problems
- Ordered Payload ReleaseONSITE INTERVIEW · Seen Jul 2026
- Decode Numeric StringONSITE INTERVIEW · Seen Jun 2026
- Tree Ancestor QueriesONSITE INTERVIEW · Seen Jun 2026
- City Infection NumberOA · Seen Jul 2025
- Minimum Tunnel Crossing TimeOA · Seen Jul 2025
- Product of Subset MaximaOA · Seen Jul 2025
- Reconstruct the Root StreamOA · Seen Jul 2025
- Binary Tree Maximum Path SumOA · Seen Aug 2023