Untitled
4 years ago in Plain Text
var TEST = function () {
function _recursionAdd(rtnNode, l1, l2) {
if (l1) {
rtnNode.val += l1.val;
l1 = l1.next;
}
if (l2) {
rtnNode.val += l2.val;
l2 = l2.next;
}
if (rtnNode.val >= 10) {
rtnNode.val -= 10;
rtnNode.next = _recursionAdd(new ListNode(1), l1, l2);
} else if (l1 && l2) {
rtnNode.next = _recursionAdd(new ListNode(0), l1, l2);
} else {
if (l1) {
rtnNode.next = l1;
} else if (l2) {
rtnNode.next = l2;
}
}
return rtnNode;
}
return {
exec: function (l1, l2) {
return _recursionAdd(new ListNode(0), l1, l2);
}
};
}();
var addTwoNumbers = function(l1, l2) {
return TEST.exec(l1, l2);
};