Java Solution Acepted


  • 0
    O

    public class Solution {

    public int addDigits(int num) {
        String numString = String.valueOf(num);
        if(numString.length()==1)
        return num;
        
        num = 0;
        for(int i = 0; i< numString.length();i++){
            num+= Integer.parseInt(Character.toString(numString.charAt(i)));
        }
        return addDigits(num);
    }
    

    }


Log in to reply
 

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