Trains the technique from
LeetCode 258Add DigitsThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
Every parcel that leaves the depot carries a tracking number num, and the printer stamps a one-digit check mark next to it.
The check mark is produced like this: add up the digits of num. If that total is still two digits or longer, add up its digits as well, and keep folding the number that way until only one digit is left. That surviving digit is the check mark.
Given num, return its check mark.
Example 1
4 + 9 + 1 + 7 = 21, and 2 + 1 = 3. Three is a single digit, so the check mark is 3.
Example 2
9 + 9 = 18, then 1 + 8 = 9.
Example 3
The digits total 15, and 1 + 5 = 6.
Example 4
The ten digits total 46, then 4 + 6 = 10, then 1 + 0 = 1. This is the largest tracking number the constraints allow.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def add_digits(num: int) -> int:public int addDigits(int num)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.