leetcode——258. 各位相加

简单题

class Solution:
    def addDigits(self, num: int) -> int:
        if num<10:
            return num
        while num>=10:
            a=str(num)
            s=0
            for i in range(len(a)):
                s+=int(a[i])
                num=s
        return num
执行用时 :48 ms, 在所有 python3 提交中击败了74.86%的用户
内存消耗 :13.7 MB, 在所有 python3 提交中击败了5.54%的用户
 
                                                                              ——2019.10.17

猜你喜欢

转载自www.cnblogs.com/taoyuxin/p/11695340.html