|
| 1 | +/** |
| 2 | + * Definition for singly-linked list. |
| 3 | + * function ListNode(val, next) { |
| 4 | + * this.val = (val===undefined ? 0 : val) |
| 5 | + * this.next = (next===undefined ? null : next) |
| 6 | + * } |
| 7 | + */ |
| 8 | +/** |
| 9 | + * @param {ListNode} l1 |
| 10 | + * @param {ListNode} l2 |
| 11 | + * @return {ListNode} |
| 12 | + */ |
| 13 | +var addTwoNumbers = function(l1, l2) { |
| 14 | + |
| 15 | +}; |
| 16 | + |
| 17 | +const myLinkedList = new LinkedList(); |
| 18 | +myLinkedList.prepend(2); |
| 19 | +myLinkedList.append(4); |
| 20 | +myLinkedList.append(3); |
| 21 | + |
| 22 | +const myLinkedList2 = new LinkedList(); |
| 23 | +myLinkedList2.prepend(5); |
| 24 | +myLinkedList2.append(6); |
| 25 | +myLinkedList2.append(4); |
| 26 | + |
| 27 | +const myLinkedList3 = new LinkedList(); |
| 28 | +myLinkedList3.prepend(0); |
| 29 | + |
| 30 | +const myLinkedList4 = new LinkedList(); |
| 31 | +myLinkedList4.prepend(0); |
| 32 | + |
| 33 | +const myLinkedList5 = new LinkedList(); |
| 34 | +myLinkedList5.prepend(9); |
| 35 | +myLinkedList5.append(9); |
| 36 | +myLinkedList5.append(9); |
| 37 | +myLinkedList5.append(9); |
| 38 | +myLinkedList5.append(9); |
| 39 | +myLinkedList5.append(9); |
| 40 | +myLinkedList5.append(9); |
| 41 | + |
| 42 | +const myLinkedList6 = new LinkedList(); |
| 43 | +myLinkedList6.prepend(9); |
| 44 | +myLinkedList6.append(9); |
| 45 | +myLinkedList6.append(9); |
| 46 | +myLinkedList6.append(9); |
| 47 | + |
| 48 | +const myLinkedList7 = new LinkedList(); |
| 49 | +myLinkedList7.prepend(1); |
| 50 | +myLinkedList7.append(2); |
| 51 | +myLinkedList7.append(3); |
| 52 | + |
| 53 | +const myLinkedList8 = new LinkedList(); |
| 54 | +myLinkedList8.prepend(4); |
| 55 | +myLinkedList8.append(5); |
| 56 | +myLinkedList8.append(6); |
| 57 | + |
| 58 | +const myLinkedList9 = new LinkedList(); |
| 59 | +myLinkedList3.prepend(9); |
| 60 | + |
| 61 | +const myLinkedList10 = new LinkedList(); |
| 62 | +myLinkedList4.prepend(9); |
| 63 | + |
| 64 | + |
| 65 | +const executeList = (l1, l2) => addTwoNumbers(l1.head, l2.head) |
| 66 | + |
| 67 | +const execute = (l1, l2) => { |
| 68 | + console.log('travers') |
| 69 | + console.log(l1.toString()); |
| 70 | + console.log(l2.toString()); |
| 71 | + const list1 = executeList(l1, l2) |
| 72 | + console.log(traversList(list1)) |
| 73 | +} |
| 74 | + |
| 75 | +execute(myLinkedList, myLinkedList2) // [2,4,3] [5,6,4] // [7,0,8] |
| 76 | +execute(myLinkedList3, myLinkedList4) // [0] [0] // [0] ??? |
| 77 | +execute(myLinkedList5, myLinkedList6) // [9,9,9,9,9,9,9] [9,9,9,9] // [8,9,9,9,0,0,0,1] |
| 78 | +execute(myLinkedList7, myLinkedList8) // [1,2,3] [4,5,6] // [5,7,9] |
| 79 | +execute(myLinkedList9, myLinkedList10) // [9] [9] // [8,1] |
0 commit comments