You are viewing a single comment's thread. Return to all comments →
python solution:
def mergeLists(head1, head2): if not head1 and not head2: return head1 if not head1: return head2 if not head2: return head1 res = SinglyLinkedListNode(None) c = res c1 = head1 c2 = head2 while c1 and c2: print(res) if c1.data <= c2.data: c.next = c1 c1 = c1.next else: c.next = c2 c2 = c2.next c = c.next if c1: c.next = c1 if c2: c.next = c2 return res.next
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 →
python solution: