Problem
Given an integer num, repeatedly add all its digits until the result has only one digit, and return it.
Algorithm
Operate according to the requirements of the topic.
Code
class Solution:
def addDigits(self, num: int) -> int:
while num > 9:
digit_sum = 0
while num:
digit_sum += num % 10
num //= 10
num = digit_sum
return num