```
class Solution {
public:
int addDigits(int num) {
//return solution1(num);
//return solution2(num);
return solution3(num);
}
private:
int solution1(int num){
return (num - 1) % 9 + 1;
}
int solution2(int num){
return num - 9 * ((num - 1)/9);
}
int solution3(int num){
if(num < 10) return num;
return solution3(num / 10 + num % 10);
}
```

};