Given an integer num, repeatedly add all its digits until the result has only one digit, and return it.

&nbsp;
Example 1:

Input: num = 38
Output: 2
Explanation: The process is
38 --&gt; 3 + 8 --&gt; 11
11 --&gt; 1 + 1 --&gt; 2 
Since 2 has only one digit, return it.


Example 2:

Input: num = 0
Output: 0


&nbsp;
Constraints:


	0 &lt;= num &lt;= 231 - 1


&nbsp;
Follow up: Could you do it without any loop/recursion in O(1) runtime?

class Solution:
    def addDigits(self, num: int) -> int:
        while num > 9:
            num = num % 10 + num // 10
        return num
class Solution {
    public int addDigits(int num) {
        if(num == 0) return 0;
        else if(num % 9 == 0) return 9;
        else return num % 9;
    }
}
class Solution {
public:
    int addDigits(int n) {
        return n < 10 ? n : addDigits(n / 10 + n % 10);
    }
};
var addDigits = function(num) {
    return 1 + (num - 1) % 9;
};
Add Digits