We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 19ac281 commit 3647270Copy full SHA for 3647270
kotlin/0043-multiply-strings.kt
@@ -0,0 +1,26 @@
1
+
2
+class Solution {
3
+ fun multiply(num1: String, num2: String): String {
4
+ if (num1=="0" || num2=="0") return "0"
5
6
+ val sum = IntArray(num1.length + num2.length)
7
+ val n1 = num1.reversed()
8
+ val n2 = num2.reversed()
9
10
+ for (i in 0 until n1.length) {
11
+ for (j in 0 until n2.length) {
12
+ var temp = (n1[i] - '0') * (n2[j] - '0') + sum[i + j]
13
+ sum[i + j + 1] += temp / 10
14
+ sum[i + j] = temp % 10
15
+ }
16
17
18
+ return StringBuilder().apply {
19
+ for(i in sum.lastIndex downTo 0) {
20
+ if (this.length == 0 && sum[i] == 0) continue
21
+ this.append(sum[i])
22
23
+ }.toString()
24
25
26
+}
0 commit comments