Simple Beginner Approach
Intuition\nIt\'s simply playing with pointers. So before referring to code, please go thoroughly with approach stated below, you\'ll definitely get it\n\n# Appr
# Intuition\nIt\'s simply playing with pointers. So before referring to code, please go thoroughly with approach stated below, you\'ll definitely get it\n\n# Approach\nLet\'s break down the stepwise approach of the given code:\n\n1. **Initialization**:\n    - A dummy node is created and its next pointer is assigned to the head of the linked list. This dummy node helps in handling cases where the head itself is a duplicate and needs to be removed.\n    - `current` pointer is initialized to point to the dummy node. This pointer will be used to traverse the linked list.\n\n2. **Traversing the Linked List**:\n    - The code enters a while loop to traverse through the linked list until `current.next` and `current.next.next` are both not None. This ensures that there are at least two nodes ahead of the current node.\n    - Inside the loop, it checks if the value of the current node\'s next node (`current.next`) is equal to the value of the next next node (`current.next.next`). This is a check for duplicate values.\n\n3. **Removing Duplicates**:\n    - If the values of `current.next` and `current.next.next` are the same, it means there\'s a duplicate. The code enters another while loop to skip over all nodes with duplicate values.\n    - Within this inner loop, it iterates until either `current.next` is None or the values of `current.next` and `current.next.next` are different. This effectively skips over all nodes with duplicate values.\n    - After the inner loop, `current.next` is adjusted to point to the node after the last duplicate node encountered, effectively removing all duplicates.\n\n4. **Moving to the Next Node**:\n    - If no duplicates are found, or after removing duplicates, `current` is updated to point to the next node in the linked list. This progression ensures traversal through the entire linked list.\n\n5. **Returning the Result**:\n    - Finally, the next node after the dummy node is returned, which effectively represents the head of the modified linked list with duplicates removed.\n\nPlease upvote ^. (As this is my first time to post solution)\n\n# Complexity\n- Time complexity:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n# Definition for singly-linked list.\n# class ListNode:\n#     def __init__(self, val=0, next=None):\n#         self.val = val\n#         self.next = next\nclass Solution:\n    def deleteDuplicates(self, head: Optional[ListNode]) -> Optional[ListNode]:\n        dummy = ListNode(0)\n        dummy.next = head\n        current  = dummy\n\n        while current.next and current.next.next:\n            if current.next.val == current.next.next.val:\n                while current.next and current.next.next and current.next.val == current.next.next.val:\n                    current.next = current.next.next\n\n                current.next = current.next.next\n\n            else:\n                current =  current.next\n\n        return dummy.next\n                \n                \n                \n\n                \n\n                \n\n\n\n```
['Linked List', 'Two Pointers', 'Python3']