Problem 258: Add Digits
思路
这其实算数学题,有现成的公式可以用。
https://en.wikipedia.org/wiki/Digital_root#Congruence_formula
public class Solution {
public int addDigits(int num) {
return 1 + (num - 1) % 9;
}
}
Last updated
Was this helpful?
这其实算数学题,有现成的公式可以用。
https://en.wikipedia.org/wiki/Digital_root#Congruence_formula
public class Solution {
public int addDigits(int num) {
return 1 + (num - 1) % 9;
}
}
Last updated
Was this helpful?