This is not the best one.
public class Solution {
public int addDigits(int num) {
if(num<10)
return num;
int sum=0;
while(num>=10)
{
sum=sum+num%10;
num=(num-num%10)/10;
}
sum=sum+num;
if(sum<10)
return sum;
else
return addDigits(sum);
}
}
原文:http://www.cnblogs.com/CathyXiaohe/p/4985395.html