if not second_list: small_node.next = first_list return new_head if __name__ == "__main__": list_1 = SinglyLinkedList() list_1.append(1) list_1.append(3) list_1.append(5) list_2 = SinglyLinkedList() list_2.append(2) list_2.append(4) list_2.append(6) print("List 1 : ") list_1.print_list() print("List 2 : ") list_2.print_list() print("Merged List : ") curr = merge_sorted_lists(list_1, list_2) while curr: print(curr.val, end="-> ") curr = curr.next print("None")
head = llist.head while head: if head.next and head.val == head.next.val: while head.next and head.val == head.next.val: head = head.next pred.next = head.next else: pred = pred.next head = head.next llist.head = sentinel.next return if __name__ == "__main__": llist = SinglyLinkedList() llist.append(1) llist.append(1) llist.append(2) llist.append(3) llist.append(3) llist.print_list() remove_duplicates_sorted_ii(llist) llist.print_list()