simple to understand,recursion


  • 1
    Z

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


Log in to reply
 

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