Solution using digital root


  • -1
    P
    class Solution {
    public:
        int addDigits(int num) {
            if(num < 10)
                return num;
            return num - 9 * floor((num-1)/(9));   
        }
    };

Log in to reply
 

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