Accepted Java recursive function solution


  • 0
    K
      public int addDigits(int num) {        
        int count;
        int sum = 0;
        if (num < 10) {
            return num;
        }
        for (int num1 = num; num1 > 0; num1 /= 10) {
    
            count = num1 % 10;
            sum += count;
        }
       return addDigits(sum);
       }

Log in to reply
 

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