Title
Given a non-negative integer num, repeatedly add the digits in each digit until the result is a single digit.
For a non-negative number, its composition is
, The previous part is a multiple of 9, we can remove it by modulo 9, in order to prevent the answer itself from being 9, we need to -1 first, then modulo.
class Solution {
public:
int addDigits(int num) {
return (num-1)%9+1;
}
};