Merge two sorted linked list of size n1 and n2. The duplicates in two linked list should be present only once in the final sorted linked list.
Input : list1: 1->1->4->5->7 list2: 2->4->7->9 Output : 1 2 4 5 7 9
Approach: Following are the steps:
- Merge the two sorted linked list in sorted manner. Refer recursive approach of this post. Let the final obtained list be head.
- Remove duplicates from sorted linked list head.
1 2 4 5 7 9
Time complexity: O(n1 + n2).
Auxiliary Space: O(1).
Exercise: Get the final sorted linked list without duplicates in a single traversal of the two lists.
- Merge K sorted Doubly Linked List in Sorted Order
- Remove duplicates from a sorted linked list
- Remove duplicates from a sorted doubly linked list
- Remove duplicates from a sorted linked list using recursion
- Remove all occurrences of duplicates from a sorted Linked List
- Merge two sorted linked lists such that merged list is in reverse order
- Sorted merge of two sorted doubly circular linked lists
- Merge K sorted linked lists | Set 1
- Merge two sorted linked lists
- Merge a linked list into another linked list at alternate positions
- Merge k sorted linked lists | Set 2 (Using Min Heap)
- Insert value in sorted way in a sorted doubly linked list
- Count duplicates in a given linked list
- Replace nodes with duplicates in linked list
- Remove duplicates from an unsorted linked list
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.