题目描述
Given a non-negative integer num
, repeatedly add all its digits until the result has only one digit.
Example:
1 |
Input: 38 |
写了几个数字之后,可以发现这个结果以9为一个循环,并且返回值为处以9后的余数。在整除的情况下,除了0返回0以外,其他都返回9(如9,18,27等)。
代码实现
1 |
class { |
题目描述
Given a non-negative integer num
, repeatedly add all its digits until the result has only one digit.
Example:
1 |
Input: 38 |
写了几个数字之后,可以发现这个结果以9为一个循环,并且返回值为处以9后的余数。在整除的情况下,除了0返回0以外,其他都返回9(如9,18,27等)。
代码实现
1 |
class { |
近期评论