Posted on 2023-04-26 21:22
Uriel 閱讀(56)
評(píng)論(0) 編輯 收藏 引用 所屬分類(lèi):
閑來(lái)無(wú)事重切Leet Code 、
大水題
將一個(gè)數(shù)字不斷加和各數(shù)位的數(shù)字,直到結(jié)果的數(shù)小于10,水題
1 #258
2 #Runtime: 23 ms (Beats 46.91%)
3 #Memory: 13.3 MB (Beat 88.20%)
4
5 class Solution(object):
6 def addDigits(self, num):
7 """
8 :type num: int
9 :rtype: int
10 """
11 while num >= 10:
12 t = num
13 num = 0
14 while t > 0:
15 num += t % 10
16 t = t // 10
17 return num