258. Add Digits


  • 0
    X
    def addDigits(self, num):
            """
            :type num: int
            :rtype: int
            """
            str_num = str(num)
            
            if len(str_num)==1:
                return num
            
            sum = 0
            
            for num in str_num:
                sum += int(num)
            
            self.addDigits(sum)
    

Log in to reply
 

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