You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.
var addStrings = function (num1, num2) {
let i = num1.length - 1;
let j = num2.length - 1;
let add = 0;
let ans = '';
while ( i >= 0 || j >= 0 || add !== 0 ) {
let x = i >= 0 ? num1[i] - '0' : 0;
let y = j >= 0 ? num2[j] - '0' : 0;
let sum = x + y + add;
ans += (sum % 10);
add = Math.floor( sum / 10 );
i -= 1;
j -= 1;
// console.log( i, j, sum, sum % 10 )
}
// console.log( ans )
return ans.split('').reverse().join('')
};
415. 字符串相加
给定两个字符串形式的非负整数 num1 和num2 ,计算它们的和。
注意:
num1 和num2 的长度都小于 5100.
num1 和num2 都只包含数字 0-9.
num1 和num2 都不包含任何前导零。
你不能使用任何內建 BigInteger 库, 也不能直接将输入的字符串转换为整数形式。
解题代码
解题思路
解题效率
The text was updated successfully, but these errors were encountered: