Relatively easy/readable approach in Python using modulo & division


  • 0
    D
    class Solution(object):
        def addDigits(self, num):
            """
            :type num: int
            :rtype: int
            """
            while(num/10 != 0):
                temp = 0
                while(num > 0):
                    temp += num%10
                    num = num/10
                num = temp
            return num

Log in to reply
 

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