LeetCode-258. Add Digits

题目

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

Example:

1
2
3
4
Input: 38
Output: 2
Explanation: The process is like: 3 + 8 = 11, 1 + 1 = 2.
Since 2 has only one digit, return it.

Follow up:

1
Could you do it without any loop/recursion in O(1) runtime?

分析

这是一个数字根的问题,此题的解法其实有很多,但是最后一句换你能在时间复杂度为1的qiang