MCPcopy Index your code
hub / github.com/neetcode-gh/leetcode / update

Function update

javascript/0043-multiply-strings.js:44–57  ·  view source on GitHub ↗
(num1, i, num2, j, buffer)

Source from the content-addressed store, hash-verified

42};
43
44var update = (num1, i, num2, j, buffer) => {
45 const curPos = i + j;
46 const prevPos = curPos + 1;
47
48 const carry = buffer[prevPos];
49 const product = getProduct(num1, i, num2, j);
50 const sum = carry + product;
51
52 const remainder = sum % 10;
53 const value = (sum - remainder) / 10;
54
55 buffer[prevPos] = remainder; /* Space O(N + M) */
56 buffer[curPos] += value; /* Space O(N + M) */
57};
58
59var getProduct = (num1, i, num2, j) => {
60 const [iNum, jNum] = [Number(num1[i]), Number(num2[j])];

Callers 1

multiplicationFunction · 0.70

Calls 1

getProductFunction · 0.85

Tested by

no test coverage detected