Given the head of a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Return the linked list sorted as well.
[0, 300].-100 <= Node.val <= 100In this problem, we are dealing with a sorted linked list. The goal is to remove all nodes that have duplicate numbers, leaving only distinct numbers from the original list.
prev and current, we can manage list traversal and modification efficiently.prev to track the last node before the sequence of duplicates.current to iterate through the list.prev’s next is linked to the node after the duplicates.prev to current.dummy.next because dummy was pointing to the beginning of the list structure we have built.