my recursive python solution


  • 0
    Y

    New to coding. Here is my naive recursive approach:

    class Solution(object):
        def addDigits(self, num):
            """
            :type num: int
            :rtype: int
            """
            sum=0
            while num>=10:
                sum+=num%10
                num=num//10
            sum+=num
            if sum<10:
                return sum
            else:
                return self.addDigits(sum)
    

    Comments are welcome!


Log in to reply
 

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