本来想看看这样行不行,结果一下就AC了,超开心
可能这道题就是十位和个位吧
Given a non-negative integer num
, repeatedly add all its digits until the result has only one digit.
For example:
Given num = 38
, the process is like: 3 + 8 = 11
, 1 + 1 = 2
. Since 2
has only one digit, return it.
int addDigits(int num) {
while(num/10!=0){
int a=0,b=0;
a=num%10;
b=(num-num%10)/10;
num=a+b;
}
return num;
}