A simple python code

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

  • 0

    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.