Simple Java Code


  • 0
    S
    public static int addDigits(int num) {
        int sum=0;
        while(num != 0 ){
            
            int last_digit = num % 10;
            sum += last_digit;
            num = num/10;
            
        }
        
        if(checkSum(sum)){
        	return addDigits(sum);
        }
    
        return sum;
    }
    
    private static boolean checkSum(int x) {
    	boolean isDoubleDigit = (x > 9 && x < 100);
    	return isDoubleDigit;

Log in to reply
 

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