What`s the Digital root?


  • 0
    B

    class Solution {
    public:
    int addDigits(int num) {

     if(num < 10)
            return num;
        int a[10];
        int i = 0;
       while(num)
        {
            a[i++] = num%10;
            num /= 10;
        }
        int temp = 0;
    
        for(int j = 0;j < i;j++)
        {
            temp = temp + a[j];
        }
    
        while(temp > 9)
        {
            int a = temp %10;
            int b = temp /10;
            temp =  a + b;
        }
        return temp;
    }
    

    };


Log in to reply
 

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