Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var addTwoNumbers = function(l1, l2) {
- let result = new ListNode(0);
- let carryOver = 0;
- let current = result;
- while (l1 !== null || l2 !== null || carryOver > 0) {
- let sum = carryOver;
- if (l1 !== null) {
- sum += l1.val;
- l1 = l1.next;
- };
- if (l2 !== null) {
- sum += l2.val;
- l2 = l2.next;
- }
- carryOver = sum >= 10 ? 1 : 0;
- current.next = new ListNode(sum % 10);
- current = current.next;
- }
- return result.next;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement