We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
class Solution { public String multiply(String num1, String num2) { if (num1.equals("0") || num2.equals("0")) return "0"; int l1 = num1.length(), l2 = num2.length(), l = l1 + l2; char[] ans = new char[l]; char[] c1 = num1.toCharArray(); char[] c2 = num2.toCharArray(); for (int i = l1 - 1; i >= 0; --i) { int c = c1[i] - '0'; for (int j = l2 - 1; j >= 0; --j) { ans[i + j + 1] += c * (c2[j] - '0'); } } for (int i = l - 1; i > 0; ++i) { // 这个地方写错了 应该是-- if (ans[i] > 9) { ans[i - 1] += ans[i] / 10; ans[i] %= 10; } } StringBuilder sb = new StringBuilder(); int i = 0; for (; ; ++i) if (ans[i] != 0) break; for (; i < ans.length; ++i) sb.append((char) (ans[i] + '0')); return sb.toString(); } }
The text was updated successfully, but these errors were encountered:
好的,已更新,只是 note 里写错了哈。
Sorry, something went wrong.
No branches or pull requests
The text was updated successfully, but these errors were encountered: