Back to problems Sign in to unlock
Leetcode
Easy
Math
Number Theory
Add Digits
Repeatedly add the digits of a non-negative integer until a single digit remains.
Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.
Problem Statement
Given a non-negative integer, repeatedly replace the number with the sum of its digits until the result has only one digit. Return that final single-digit value.
For example, if the number is 38, then 3 + 8 = 11, and 1 + 1 = 2, so the answer is 2.
Input Format
- One non-negative integer
num. - The value may be provided as an integer.
Output Format
- Return the single digit obtained after repeatedly summing the digits of
num.
Constraints
0 <= num- The final answer is always a single digit from
0to9.
Examples
Sample cases returned by the problem API.
Example 1
Input
num = 38
Output
2
Explanation
3 + 8 = 11, and 1 + 1 = 2.
Example 2
Input
num = 0
Output
0
Explanation
The number is already a single digit.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.
Guided hints
Editorial and discussion links
Concept map and variants
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.