8ms, 9 line solution


  • 0
    S

    9 line, 8ms c++ solution using recursive method.

    int addDigits(int num) {
        if(num<10) return num;
        int res=0;
        while(num){
            res+=(num%10);
            num/=10;
        }
        return addDigits(res);
    }

Log in to reply
 

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