Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.

Input: 38

Output:

Explanation: The process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, return it.

Could you do it without any loop/recursion in O(1) runtime?

```public class Program {

public static void Main(string[] args) {
var n = 38;
Console.WriteLine(res);

n = 513;
Console.WriteLine(res);

n = 66;
Console.WriteLine(res);

}

private static int AddDigits(int num) {
var length = num.ToString().Length;
if(length == 1) return num;
var res = 0;
while(length > 1) {
res = 0;
for(var i = 0; i < length; i++) {
res += int.Parse(num.ToString()[i].ToString());
}
num = res;
length = num.ToString().Length;
}
return res;
}

private static int AddDigits2(int num) {
if(num < 10) return num;
var temp = num;
var sum = 0;
while(temp != 0) {
sum += temp % 10;
temp /= 10;
}
}

private static int AddDigits3(int num) {
//if(num == 0) return 0;
//var result = num % 9;
//if(result == 0) return 9;
//return result;
return num == 0 ? 0 : (num % 9 == 0 ? 9 : num % 9);
}

}```

```2
9
3```

(2)