Add Digits

Problem Id: 258 Difficulty: Easy


Intuition

Solution


class Solution:
    def addDigits(self, num: int) -> int:
        if num <= 9:
            return num
        digits = []
        while num != 0:
            digits.append(num % 10)
            num = num // 10
        return self.addDigits(sum(digits))