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 } list1
10+ * @param {ListNode } list2
11+ * @return {ListNode }
12+ */
13+ var mergeTwoLists = function ( list1 , list2 ) {
14+
15+ } ;
16+
17+ const myLinkedList = new LinkedList ( ) ;
18+ myLinkedList . prepend ( 1 ) ;
19+ myLinkedList . append ( 2 ) ;
20+ myLinkedList . append ( 4 ) ;
21+
22+ const myLinkedList2 = new LinkedList ( ) ;
23+ myLinkedList2 . prepend ( 1 ) ;
24+ myLinkedList2 . append ( 3 ) ;
25+ myLinkedList2 . append ( 4 ) ;
26+
27+ const myLinkedList3 = new LinkedList ( ) ;
28+
29+ const myLinkedList4 = new LinkedList ( ) ;
30+
31+ const myLinkedList5 = new LinkedList ( ) ;
32+
33+ const myLinkedList6 = new LinkedList ( ) ;
34+ myLinkedList6 . prepend ( 0 ) ;
35+
36+ const executeList = ( list , list2 ) => mergeTwoLists ( list . head , list2 . head )
37+
38+ const execute = ( list , list2 ) => {
39+ console . log ( 'travers' )
40+ console . log ( list . toString ( ) ) ;
41+ console . log ( list2 . toString ( ) ) ;
42+ const list1 = executeList ( list , list2 )
43+ console . log ( traversList ( list1 ) )
44+ }
45+
46+ execute ( myLinkedList , myLinkedList2 ) // 1,2,4 1,3,4 // 1,1,2,3,4,4
47+ execute ( myLinkedList3 , myLinkedList4 ) // [] [] // []
48+ execute ( myLinkedList5 , myLinkedList6 ) // [] [0] // [0]
49+
50+
0 commit comments