This is the Simple Solution


  • 0
    R
    public class Solution {
    public int addDigits(int n) {
        if(n < 10)
        return n;
        int rev =0, r =0;
        while(true){
            
            while(n > 0){
                rev = rev+ n%10;
                n /=10;
            }
            
            if(rev >=10){
                n = rev;
                rev = 0;
            }
            else
            break;
        }
        
        return rev;
    }
    

    }


Log in to reply
 

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