Python recursive solution 68ms


  • 0
    Y
    def addDigits(num):
    ret = 0
    while num >0:
        remain = num %10
        num = num//10
        ret += remain
    if ret < 10:
        return ret
    return addDigits(ret)

Log in to reply
 

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