Share my simple to understand,no tricky Java solution


  • 1
    X
    public class Solution {
    public int addDigits(int num) {
        String str = String.valueOf(num);
        while(str.length()>1){
            num =0;
            for(int i =0;i<str.length();i++){
                num=num+str.charAt(i)-'0';
            }
            str = String.valueOf(num);
        }
        return num;
    }
    

    }


Log in to reply
 

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