258. 各位相加
为保证权益,题目请参考 258. 各位相加(From LeetCode).
解决方案1
Python
python
# 258. 各位相加
# https://leetcode-cn.com/problems/add-digits/
class Solution:
def addDigits(self, num: int) -> int:
while num >= 10:
s = 0
for n in list(str(num)):
s += int(n)
num = s
return num
if __name__ == "__main__":
so = Solution()
print(so.addDigits(38))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16