Add Digits - without loop/recursion


  • 0
    D
    public int addDigits(int num) {
        if (num == 0)
            return 0;
        num = num % 9;
        if (num == 0)
            return 9;
        return num;
    }
    

Log in to reply
 

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