You are viewing a single comment's thread. Return to all comments →
Javascript solution:
function mergeLists(head1, head2) { let head, list = getItems(head2).split(',') .concat(getItems(head1).split(',')) .sort((a,b) => b-a) for(let i =0; i<list.length; i++ ){ let res = new SinglyLinkedListNode(list[i]) res.next = head head = res } return head } function getItems(item){ let list = [] Object.entries(item).forEach((a,b) =>{ if(typeof(a[1]) == 'object' && a[1] != null) list.push(getItems(a[1])) if(typeof(a[1]) == 'number') list.push(a[1]) }) return list.toString() }
Seems like cookies are disabled on this browser, please enable them to open this website
Merge two sorted linked lists
You are viewing a single comment's thread. Return to all comments →
Javascript solution: