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.
result = SinglyLinkedList()
while head1 or head2:
if not head1:
result.insert_node(head2.data)
head2 = head2.next
elif not head2:
result.insert_node(head1.data)
head1 = head1.next
elif head1 and head2:
if head1.data <= head2.data:
result.insert_node(head1.data)
head1 = head1.next
else:
result.insert_node(head2.data)
head2 = head2.next
return result.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 →