Simple C++ Loop Solution


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

Log in to reply
 

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