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.

思路:取各位数字相加,直至相加结果为一位数(<9),考虑边界情况

思路:规律是直接与9的取余

 

posted on 2015-08-25 15:27  laclt  阅读(303)  评论(0编辑  收藏  举报