Tap here to switch tabs
Problem
Submissions

Problem: Add Digits

Add Digits repeatedly sums the decimal digits of a nonnegative integer until one digit remains, then returns that digit. Can you do it without loops or recursion?

Statement

Given an integer num, repeatedly sum all of its digits until the resulting value is a single digit, then return that value.

Note: Could you solve this without any loop or recursion in O(1)O(1) runtime?

Constraints:

  • 0≤0 \leq num ≤231−1\leq 2^{31} - 1

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Add Digits

Add Digits repeatedly sums the decimal digits of a nonnegative integer until one digit remains, then returns that digit. Can you do it without loops or recursion?

Statement

Given an integer num, repeatedly sum all of its digits until the resulting value is a single digit, then return that value.

Note: Could you solve this without any loop or recursion in O(1)O(1) runtime?

Constraints:

  • 0≤0 \leq num ≤231−1\leq 2^{31} - 1