Java 2ms solution


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

Log in to reply
 

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