Simple C++ Solution


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

Log in to reply
 

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