A Python Solution


  • 0
    P
    class Solution(object):
        def addDigits(self, num):
            """
            :type num: int
            :rtype: int
            """
            while len(str(num)) != 1:
                str_num = str(num)
                num = sum([int(i) for i in str_num])
            return num

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.