每次思考都是一次进步
简单做法:按照题目来暴力解,双重循环求直到该数小于10
class Solution {
public:
int addDigits(int num) {
int sum=0;
while(num>=10)
{
while(num>0)
{
sum+=num%10;
num/=10;
}
num=sum;
sum=0;
}
return num;
}
};
标签:10,int,相加,while,力扣,num%,258,num,sum
来源: https://blog.csdn.net/qq_50917103/article/details/120879258