We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e5d3bb4 commit ee2048bCopy full SHA for ee2048b
공예영/6주차/0043-multiply-strings/0043-multiply-strings.js
@@ -0,0 +1,36 @@
1
+/**
2
+ * @param {string} num1
3
+ * @param {string} num2
4
+ * @return {string}
5
+ */
6
+var multiply = function(num1, num2) {
7
+
8
+ if (num1 === "0" || num2 === "0") return "0";
9
10
+ const m = num1.length;
11
+ const n = num2.length;
12
13
+ const res = new Array(m + n).fill(0);
14
15
+ for (let i = m - 1; i >= 0; i--) {
16
+ for (let j = n - 1; j >= 0; j--) {
17
+ const mul = num1[i] * num2[j];
18
19
+ const p1 = i + j; // 십의 자리
20
+ const p2 = i + j + 1; // 일의 자리
21
22
+ const sum = mul + res[p2];
23
24
+ res[p2] = sum % 10;
25
+ res[p1] += Math.floor(sum / 10);
26
+ }
27
28
29
30
+ while (res[0] === 0) {
31
+ res.shift();
32
33
34
+ return res.join('');
35
36
+};
0 commit comments