258. 各位相加
使用递归就行
class Solution {
public int addDigits(int num) {
if(num < 10) return num;
int next = 0;
while(num != 0){
next = next + num % 10;
num /= 10;
}
return addDigits(next);
}
}

浙公网安备 33010602011771号