LinkedList/remove_duplicates_sorted_list library
๐งน Remove Duplicates from Sorted Linked List โ in-place deduplication
Removes duplicate consecutive values from a sorted singly linked list by
rewiring next pointers. The function is generic and does not allocate new
nodes; it relies on equality (==) for value comparisons.
Contract:
- Inputs:
head(nullable linked list head) where values are sorted in non-decreasing order. - Output: head of the deduplicated list (nullable). If
headisnull, returnsnull. - Error modes: behavior is undefined if the list is unsorted.
Complexity: Time O(n), Space O(1).
Example:
final head = LinkedListNode.fromList([1,1,2,3,3]);
final deduped = removeDuplicatesSortedList(head);
// deduped: [1,2,3]
Functions
-
removeDuplicatesSortedList<
T> (LinkedListNode< T> ? head) โ LinkedListNode<T> ?