package miscellaneous.math.arithmetic.add.lc258_adddigits;

/**
 * Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.
 * For example: Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, return it.
 * Follow up: Could you do it without any loop/recursion in O(1) runtime?
 */
public class Solution {

    public int addDigits(int num) {
        return num - 9*((num-1)/9);
    }

}

@@ -387,28 +387,320 @@
     
-public int addDigits
+// My 2AC: use loop%0A    public int addDigits(int num) %7B%0A        while (num %3E= 10) %7B%0A            int sum = 0;%0A            while (num %3E 0) %7B%0A                sum += num %25 10;%0A                num /= 10;%0A            %7D%0A            num = sum;%0A        %7D%0A        return num;%0A    %7D%0A%0A    // My 1AC%0A    public int addDigits1
 (int

leetcode-258 add digits