The singly linked list starting at head is sorted in nondecreasing order. Remove duplicate nodes so that each distinct value remains exactly once, and return the head of the resulting list. Preserve the sorted order. In the examples and test inputs, an array lists node values from head to tail; [] represents an empty list.
Example 1:
Input: head = [0,0,1,2,2,2]
Output: [0,1,2]Explanation: Keep one node with value 0, the node with value 1, and one node with value 2. The resulting chain is 0 -> 1 -> 2.
Example 2:
Input: head = [5,5,5]
Output: [5]Explanation: All three nodes have the same value. Keep one node with value 5.
Example 3:
Input: head = []
Output: []Explanation: The input list is empty, so there are no nodes to remove and the result is empty.
Constraints:
- The list contains between
0and300nodes. -100 <= Node.val <= 100- Node values are sorted in nondecreasing order.