java stupid recursion


  • 1
    M
    public class Solution {
        public int addDigits(int num) {
            int sum = 0;
            while (num > 0){
                sum += (num % 10);
                num = num/10;
            }
            if (sum < 10){
                return sum;
            }
            return addDigits(sum);
        }
    }

Log in to reply
 

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