2ms Java solution


  • 0
    Y

    public class Solution {
    public int addDigits(int num) {
    if(num<10) return num;
    int sum;
    while(num>9){
    sum=0;
    for(;num>0;num=num/10){
    sum+=num%10;
    }
    num=sum;
    }
    return num;
    }
    }


  • 0
    M

    Question said no looping, so the while loop is breaking that.


Log in to reply
 

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