题目:
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.
分析:
一、我想到的方法是递归相加咯
二、还是应该先数学分析,举例、找规律dr(n)=1+((n-1) mod 9)