Remove Duplicates from Sorted List
Problem statement
Given the head of a nondecreasing singly linked list, delete repeated nodes so that each value appears exactly once. Return the head of the same list after relinking its existing nodes.
Function
deleteDuplicates(head: ListNode) → ListNodeExamples
Example 1
head = [1,1,2]return = [1,2]The second node with value one is removed.
Example 2
head = [1,1,2,3,3]return = [1,2,3]Each repeated run is reduced to one node.
Constraints
- The list contains between
0and10^5nodes. -10^9 <= Node.val <= 10^9.- The list is sorted in nondecreasing order.