29.leetcode题目258: Add Digits

题目:

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 = 111 + 1 = 2. Since 2 has only one digit, return it.


分析:

一、我想到的方法是递归相加咯

二、还是应该先数学分析,举例、找规律dr(n)=1+((n-1)  mod  9)

你可能感兴趣的:(29.leetcode题目258: Add Digits)