My c++ Solution 3ms


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

Log in to reply
 

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