Accepted 8ms c++ solution. Not a good solution.


  • 0

    Here is not a good solution!

    class Solution {
    public:
        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.