# 其它

# 大数相乘

var multiply = function(num1, num2) {
  if (num1 === "0" || num2 === "0") {
    return "0";
  }
  var l1 = num1.length,
    l2 = num2.length,
    p = new Array(l1 + l2).fill(0);
  for (var i = l1; i--; ) {
    for (var j = l2; j--; ) {
      var tmp = num1[i] * num2[j] + p[i + j + 1];
      p[i + j + 1] = tmp % 10;
      p[i + j] += 0 | (tmp / 10);
    }
  }
  while (p[0] === 0) {
    p.shift();
  }
  return p.join("");
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
最后更新时间: 1/25/2021, 2:35:02 PM