We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Python3. Hope they don't mind me reusing their list class :P
defmergeLists(head_1:SinglyLinkedListNode|None,head_2:SinglyLinkedListNode|None)->SinglyLinkedListNode|None:merged=SinglyLinkedList()whilehead_1orhead_2:min_head=min((head_1,head_2),key=lambdahead:head.dataifheadelsefloat('inf'))merged.insert_node(min_head.data)# iterate the source listifmin_head==head_1:head_1=head_1.nextelse:head_2=head_2.nextreturnmerged.head
Cookie support is required to access HackerRank
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 →
Python3. Hope they don't mind me reusing their list class :P