python leetcode 258. 各位相加

人生苦短,我用python

我感覺我這種做法太邪惡了。。。

class Solution:
    def addDigits(self, num):
        """
        :type num: int
        :rtype: int
        """
        num=str(num)#變成字符串來進行處理
        count=0
        while len(num)!=1:
            for i in num:
                count += int(i)
            num=str(count)
            count=0

        return int(num)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章