Remove Duplicates from Sorted List II [C++]
IntuitionTo remove duplicates from a sorted linked list, we need to ensure that each value appears only once. Since the list is sorted, duplicates will be adjac
# Intuition
To remove duplicates from a sorted linked list, we need to ensure that each value appears only once. Since the list is sorted, duplicates will be adjacent to each other. We can traverse the list and skip over nodes that have the same value as the current node.

# Approach
1. **Dummy Node**: Use a dummy node to simplify edge cases, such as when the list is empty or when the first few nodes are duplicates.
2. **Two Pointers**: Use two pointers, `prev` and `head`. `prev` will point to the last node that has no duplicates, and `head` will traverse the list.
3. **Check for Duplicates**: As we traverse the list, if we find that the current node's value is the same as the next node's value, we skip all nodes with that value.
4. **Update Pointers**: If no duplicates are found, we move the `prev` pointer forward. Otherwise, we update `prev->next` to skip the duplicates.
5. **Return Result**: Finally, return the modified list starting from `dummy.next`.

# Complexity
- **Time Complexity**: O(n), where n is the number of nodes in the linked list. We traverse the list once.
- **Space Complexity**: O(1), as we are using a constant amount of extra space.

# Code
```cpp
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head) {
        ListNode dummy(0, head);
        ListNode* prev = &dummy;

        while (head) {
            if (head->next && head->val == head->next->val) {
                while (head->next && head->val == head->next->val) {
                    head = head->next;
                }
                prev->next = head->next;
            } else {
                prev = prev->next;
            }
            head = head->next;
        }
        return dummy.next;
    }
};
```

### Explanation
1. **Dummy Node**: The dummy node is created to handle cases where the head of the list might be a duplicate. It points to the head of the list.
2. **Traversal**: We start traversing the list with `head` pointing to the first node.
3. **Duplicate Check**: If the current node's value is the same as the next node's value, we enter a loop to skip all nodes with that value.
4. **Update Pointers**: After skipping duplicates, we update `prev->next` to point to the node after the last duplicate. If no duplicates are found, we simply move `prev` forward.
5. **Continue Traversal**: We continue this process until we reach the end of the list.
6. **Return Result**: The modified list, starting from `dummy.next`, is returned as the result.
['C++']