Untitled
4 years ago in Plain Text
var TEST = function () {
function _handleExist(l1, l2) {
let sum = NaN;
let isAdd = false;
let someOneIsNull = false;
while (true) {
sum = isAdd ? 1 : 0;
sum += l1 ? l1.val : 0;
sum += l2 ? l2.val : 0;
isAdd = sum >= 10;
if (isAdd) {
sum-=10;
}
if (l1) {
l1.val = sum;
if (someOneIsNull && !l1.next) {
l1.next = isAdd ? new ListNode(1) : null;
return 1;
}
l1 = l1.next;
someOneIsNull = someOneIsNull || !l1;
}
if (l2) {
l2.val = sum;
if (someOneIsNull && !l2.next) {
l2.next = isAdd ? new ListNode(1) : null;
return 2;
}
l2 = l2.next;
someOneIsNull = someOneIsNull || !l2;
}
}
}
return {
exec: function (l1, l2) {
return (_handleExist(l1, l2) === 1) ? l1 : l2;
}
};
}();