Skip to content

Instantly share code, notes, and snippets.

@shixiaoyu
Created July 23, 2019 05:04
Show Gist options
  • Save shixiaoyu/f4c1fb7b4f5e55a073c189cc2690bce2 to your computer and use it in GitHub Desktop.
Save shixiaoyu/f4c1fb7b4f5e55a073c189cc2690bce2 to your computer and use it in GitHub Desktop.
public int addDigits(int num) {
assert num >= 0;
while (num / 10 > 0) {
num = this.calDigitSum(num);
}
return num;
}
private int calDigitSum(int num) {
int res = 0;
while (num > 0) {
res += num % 10;
num = num / 10;
}
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment