A simple python code


  • 2
    H
        def addDigits(self, num):
        """
        :type num: int
        :rtype: int
        """
        
        while num>=10:
            s=str(num)
            num = reduce(lambda x,y: int(x)+int(y), s)
            
        return num

  • 0
    X

    Delighted to see someone not using magic 9!
    mine is recursive

    def addDigits(self, num):
        return self.addDigits(sum(map(int,str(num)))) if num>10 else num
    

Log in to reply
 

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