【leetcode】(每日抑题 258 各位相加)

在这里插入图片描述
代码实现

int addDigits(int num){
    
    
 if(num==0)
 {
    
    
     return false;
 }
 int ans=0;
 while(num)
 {
    
    
     ans+=num%10;
     num/=10;
 }
 return ans<10 ? ans : addDigits(ans);
}

猜你喜欢

转载自blog.csdn.net/qq_45657288/article/details/106151087