python学习之——Add Digits

it2022-05-05  117

Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.

For example:

Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, return it.

思路:取各位数字相加,直至相加结果为一位数(<9),考虑边界情况

思路:规律是直接与9的取余

 

转载于:https://www.cnblogs.com/cloverclt/p/4757590.html

相关资源:digits.zip

最新回复(0)