两个超大的数字相加
Posted wuxie
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了两个超大的数字相加相关的知识,希望对你有一定的参考价值。
function largeCount(f, t) { f += ""; t += ""; let fl = f.length, tl = t.length, arr = [], i = 0, spacing = fl - tl, len = 0, lastMan = [], fr = f.split("").reverse(), tr = t.split("").reverse(), current = 0, curr = 0, isT, maxLen; if (spacing > 0) { len = tl; lastMan = fr; maxLen = fl; } else { len = fl; lastMan = tr; maxLen = tl; } function course(current, i) { if (current > 9) { arr[i] = current % 10; arr[i + 1] = 1; return true; } else { arr[i] = current; return false; } } for (; i < len;) { curr = arr[i] ? arr[i] : 0; current = fr[i] * 1 + tr[i] * 1 + curr * 1; course(current, i++); if (i === len) { if (arr[i]) { do { curr = lastMan[i]; if (curr) { current = lastMan[i] * 1 + arr[i] * 1; isT = course(current, i++); } else { isT = false; } } while (isT && i < maxLen); } arr = [...arr, ...lastMan.slice(i)]; } } return arr.reverse().join(""); }
以上是关于两个超大的数字相加的主要内容,如果未能解决你的问题,请参考以下文章