466. Remove Duplicates From an Unsorted Linked List
Given the head of a linked list, find all the values that appear more than once in the list and delete the nodes that have any of those values.
Return the linked list after the deletions.
Example 1:
Input: head = [1,2,3,2]
Output: [1,3]
Explanation: 2 appears twice in the linked list, so all 2's should be deleted. After deleting all 2's, we are left with [1,3].
Example 2:
Input: head = [2,1,1,2]
Output: []
Explanation: 2 and 1 both appear twice. All the elements should be deleted.
Now Your Turn!
Pick the correct output for the given inputConsider the linked list [5,6,5,7,8,6,9]. What will be the resulting list after removing duplicates?
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- The number of nodes in the list is in the range [1, 105]
- 1 <= Node.val <= 105