key: note that 9%9=0, and -1%9 = -1
Runtime: 8 ms/ beats 52.315
Reference: discuss
class Solution {
public:
int addDigits(int num) {
return 1+(num - 1)%9;
}
};
key: note that 9%9=0, and -1%9 = -1
Runtime: 8 ms/ beats 52.315
Reference: discuss
class Solution {
public:
int addDigits(int num) {
return 1+(num - 1)%9;
}
};