2ms using recursion in Java


  • 1

    '''
    public int addDigits(int num) {
    if(num<10) {return num;}
    else{
    int sum = 0;
    sum += num % 10;
    num /=10;
    sum += num;
    return addDigits(sum);
    }

    }
    

    '''


Log in to reply
 

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