c++ solution


  • 0
    D

    class Solution {
    public:
    int addDigits(int num) {
    int sum=num;
    while(sum>=10)
    {
    sum=0;
    while(num>0)
    {
    sum+=num%10;
    num/=10;
    }
    num=sum;
    }
    return sum;
    }
    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.