leetcode [#258] | GCidea's blog
目录1. 题目2. 解决方案3. 注意事项
题目Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.
For example:
Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, return it.
解决方案12345678910111213141516public class Solution { public int addDigits(int num) { int result; if (num < 10) { result = num; } else { String num2str = Integer.toString(num); int newNum = 0; f...阅读全文
题目Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.
For example:
Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, return it.
解决方案12345678910111213141516public class Solution { public int addDigits(int num) { int result; if (num < 10) { result = num; } else { String num2str = Integer.toString(num); int newNum = 0; f...阅读全文