Without two pointers, beats 100%
UPVOTE PLEASE ❤️IntuitionThe problem requires removing all duplicates from a sorted linked list, such that only unique elements remain. My first thought was to
### UPVOTE PLEASE ❤️

# Intuition
The problem requires removing all duplicates from a sorted linked list, such that only unique elements remain. My first thought was to iterate through the list and delete all consecutive duplicate nodes.

# Approach
1. Create a dummy node (`ans`) pointing to the head of the list. This ensures that even if the head node is removed, the rest of the list can still be accessed.
2. Use a pointer (`cur`) starting from the dummy node to traverse the list.
3. For each node, check if the current node and the next node have the same value:
   - If they do, find the value of the duplicate and skip all nodes with that value.
   - If they don’t, move the pointer to the next node.
4. Return the list starting from the node after the dummy (`ans.next`).

# Complexity
- **Time complexity:**  
  $$O(n)$$ — where $$n$$ is the number of nodes in the linked list. Each node is visited once.

- **Space complexity:**  
  $$O(1)$$ — No additional data structures are used.

# Code
```java
class Solution {
    public ListNode deleteDuplicates(ListNode head) {
        ListNode ans = new ListNode(1000, head); // Dummy node to handle edge cases
        ListNode cur = ans; 

        while (cur.next != null && cur.next.next != null) {
            if (cur.next.val == cur.next.next.val) { // Check if duplicates exist
                int val = cur.next.val;
                while (cur.next != null && cur.next.val == val) { // Skip all duplicates
                    cur.next = cur.next.next;
                }
            } else {
                cur = cur.next; // Move to the next node
            }
        }

        return ans.next; // Return the modified list starting after the dummy node
    }
}
['Linked List', 'Iterator', 'Java']