方法一:
class Solution {
public int addDigits(int num
) {
while(num
>9) {
int a
=num
/10;
int b
=num
%10;
num
=a
+b
;
}
return num
;
}
}
方法二:
class Solution {
public int addDigits(int num
) {
if(num
>9) {
num
=addDigits(num
/10+num
%10);
}
return num
;
}
}
转载请注明原文地址: https://lol.8miu.com/read-210.html