Remove Duplicates from a Sorted Linked List
Problem statement
Remove repeated values from the sorted linked list so exactly one node remains for each distinct value. Preserve nondecreasing order. Keep one representative from an entire equal-value run; do not delete all occurrences of a repeated value. You may modify the input links in place.
Function
deduplicateList(head: ListNode) → ListNodeExamples
Example 1
head = [1,1,2,3,3]return = [1,2,3]The runs [1,1], [2] and [3,3] each contribute one node.
Example 2
head = []return = []An empty list has no values to retain.
Constraints
0 <= head.length <= 500.-1000000 <= head[i] <= 1000000.- The list is acyclic and its values are nondecreasing.