var addStrings = function(num1, num2) {
let res = [],
i = num1.length - 1,
j = num2.length - 1,
carry = 0
while (i >= 0 || j >= 0) {
const n1 = i < 0 ? 0 : parseInt(num1[i])
const n2 = j < 0 ? 0 : parseInt(num2[j])
const temp = n1 + n2 + carry
carry = ~~(temp / 10)
res.push(temp % 10)
i--
j--
}
if (carry) {
res.push(carry)
}
return res.reverse().join("")
};
Runtime: 64 ms, faster than 79.98% of JavaScript online submissions for Add Strings.
Memory Usage: 36.4 MB, less than 37.50% of JavaScript online submissions for Add Strings.
Runtime: 52 ms, faster than 60.04% of Python3 online submissions for Add Strings.
Memory Usage: 13.7 MB, less than 5.55% of Python3 online submissions for Add Strings.
Runtime: 40 ms, faster than 92.18% of Python3 online submissions for Add Strings.
Memory Usage: 13.9 MB, less than 5.55% of Python3 online submissions for Add Strings.
Runtime: 4 ms, faster than 53.77% of Go online submissions for Add Strings.
Memory Usage: 6.8 MB, less than 60.00% of Go online submissions for Add Strings.