Java solution


  • 0
    P
    class Solution {
        public int addDigits(int num) {
            while (num>=10){
                
                int temp = num;
                int sum=0;
                while (temp>0){                
                    sum = sum+temp%10;
                    temp=temp/10;                                                                
                }
                num=sum;            
            }
            
            return num;
        }
    }
    

Log in to reply
 

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