Python solution


  • 1
    L

    class Solution(object):
    def addDigits(self, num):
    while num/10!=0:
    num=num%10+num/10
    return num


  • 0
    Y

    class Solution:
    # @param {integer} num
    # @return {integer}
    def addDigits(self, num):
    while num > 9:
    c = 0
    while num:
    c += num % 10
    num /= 10
    num = c
    return num


  • 0
    Y

    class Solution:
    def addDigits(self, num):
    while num > 9:
    c = 0
    while num:
    c += num % 10
    num /= 10
    num = c
    return num


Log in to reply
 

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