Easy solution based on Math


  • 2
    L
    int addDigits(int num) {
            if(num==0)
                return 0;
            int result = num%9;
            if(result==0)
                return 9;
            else
                return result;
        }

Log in to reply
 

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