Created
July 23, 2019 05:04
-
-
Save shixiaoyu/f4c1fb7b4f5e55a073c189cc2690bce2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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