[leetcode]258. Add Digits
Analysis
厉害的人总是那么的厉害呀~—— [菜鸡反省中~]
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.
简单题,直接看代码吧。
Implement
class Solution {
public:
int addDigits(int num) {
while(1){
if(num < 10)
return num;
int tmp = num;
num = 0;
while(tmp){
num += tmp%10;
tmp /= 10;
}
}
}
};
1233




被折叠的 条评论
为什么被折叠?



