【题目描述】
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.
Example
Given num = 38.
The process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, return 2.
给出一个非负整数 num,反复的将所有位上的数字相加,直到得到一个一位的整数。
样例
给出 num = 38。
相加的过程如下:3 + 8 = 11,1 + 1 = 2。因为 2 只剩下一个数字,所以返回 2。
【题目链接】
www.lintcode.com/en/problem/add-digits/
【题目解析】
最终数字和不可能大于10,最大值为9,则运算和模9运算有关,求该整数除以9的余数。
【参考答案】