Two method. C++ One is math-method , another is a while inside a while .


  • 0
    B

    one:
    while(num/10>0)
    {
    int sum = 0;
    while(num>0)
    {
    sum +=num%10;
    num = num/10;
    }
    num = sum;
    return num;

    another :
    return (num-1)%9 + 1;
    }


Log in to reply
 

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