Leetcode 258 Add Digits
class Solution2 {
public:
int addDigits(int num) {
while(num >= 10)
{
//逐位相加
//int tmp1 = num % 10;
// int tmp2 = num / 10;
// num = tmp1 + tmp2;
num = (num/10) + num %10;
}
return num;
//或直接找规律……神奇
//return 1 + (num-1)%9;
}
};