## Approach

Let's take an example

```.css-ds3kc{display:table-row;}.css-1t8atru{display:table-cell;opacity:0.5;padding-right:var(--chakra-space-6);-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;text-align:right;}1.css-2qghsv{display:table-cell;}123 + 292
31 2 340 2 95-----61 5 27
83 + 9 = 12, takes 2, carries 192 + 2 = 4, plus carry of 1, results in 5, takes 5101 + 0 = 1, takes 111
12final result is 152```

## Implementation

```1var addStrings = function (num1, num2) {2  const maxLength = Math.max(num1.length, num2.length)3  num1 = num1.padStart(maxLength, "0").split("").reverse()4  num2 = num2.padStart(maxLength, "0").split("").reverse()5
6  const res = []7  let carry = 08
9  for (let i = 0; i < maxLength; i++) {10    const digitSum = Number(num1[i]) + Number(num2[i]) + carry11    res.push(digitSum % 10)12    carry = Math.floor(digitSum / 10)13  }14
15  // in case we have carry leftover16  carry && res.push(carry)17
18  return res.reverse().join("")19}```

Original problem

leetcode

string

math

## Next Post

LeetCode: Sort List

Aug 29, 2022

Yeah I skipped the follow-up

## Previous Post

LeetCode: Multiply Strings

Aug 28, 2022

Will make this better. Word promised!

Search Posts