Help: recursion solution always returns null


  • 0
    L
    class Solution(object):
        def addDigits(self, num):
            """
            :type num: int
            :rtype: int
            """
            if len(list(str(num))) == 1:
                return num
            else:
                numl = list(str(num))
                nnum = [int(p) for p in numl]
                self.addDigits(sum(nnum))
    

    For test input of 10 or 100, the code above returns null... Could someone enlighten me why? Thanks..


Log in to reply
 

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