Skip to content

Instantly share code, notes, and snippets.

@wenweixu
Created September 22, 2019 19:12
Show Gist options
  • Save wenweixu/73bac7a24322059385629724a89146df to your computer and use it in GitHub Desktop.
Save wenweixu/73bac7a24322059385629724a89146df to your computer and use it in GitHub Desktop.
def mergeLists(head1, head2):
llist3 = SinglyLinkedList()
while head1 or head2:
if head1 == None:
llist3.insert_node(head2.data)
head2 = head2.next
elif head2 == None:
llist3.insert_node(head1.data)
head1 = head1.next
elif head1.data >= head2.data:
llist3.insert_node(head2.data)
head2 = head2.next
elif head2.data > head1.data:
llist3.insert_node(head1.data)
head1 = head1.next
return llist3.head
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment