Skip to content

Practice Add Digits

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#258
LeetCode Problem

Add Digits

Problem Statement

Given an integer num, repeatedly add all its digits until the result has only one digit, and return it. Example 1: Example 2: Constraints: Follow up: Could you do it without any loop/recursion in O(1) runtime?

Source: Add Digits on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
num = 38
Output
2

# Example 2

Input
num = 0
Output
0

Constraints

0 <= num <= 2^31 - 1

Related LeetCode Problems

Practice more problems similar to Add Digits.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.