My Java Solution


  • 0
    J
    public class Solution {
        public int addDigits(int num) {
            String sum_str = String.valueOf(num);
            
            if(sum_str.length() != 1){
                int result = 0;
                for(int i = 0; i < sum_str.length(); i++){
                   result += Integer.parseInt(new Character(sum_str.charAt(i)).toString());
                }
                num = addDigits(result);
            }
            return num;
        }
    }

Log in to reply
 

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