LeetCode 258, Easy. Topics: Math, Simulation, Number Theory. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 17 parametrized pytest cases, and a playground notebook:
Problem
Given an integer num, repeatedly add all its digits until the result has only one digit, and return it.
Examples
Constraints
Follow up: Could you do it without any loop/recursion in O(1) runtime?
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
Last modified on September 7, 2026