```
class Solution(object):
def addDigits(self, num):
if num==0: return 0
return 1 + (num-1)%9
```

Explanation (from Wolfram Alpha):

The digital root `dr(n)`

of an integer `n`

can be computed without actually performing the iteration using the simple congruence formula:

`= 1 + [n-1(mod 9)]`