✅ EASY C++ SOLUTION ☑️
PLEASE UPVOTE MY SOLUTION IF YOU LIKE IT\n# CONNECT WITH ME\n### https://www.linkedin.com/in/pratay-nandy-9ba57b229/\n#### https://www.instagram.com/pratay_nand
# **PLEASE UPVOTE MY SOLUTION IF YOU LIKE IT**\n# **CONNECT WITH ME**\n### **[https://www.linkedin.com/in/pratay-nandy-9ba57b229/]()**\n#### **[https://www.instagram.com/_pratay_nandy_/]()**\n\n# Approach\n\n### Explanation:\n\n1. `ListNode *dummy = new ListNode(0, head);`: Create a new ListNode with a value of 0 and link it to the original head of the list. This dummy node simplifies the handling of edge cases.\n\n2. `ListNode *prev = dummy;`: Initialize a pointer `prev` pointing to the dummy node. This will be used to modify the `next` pointer of nodes with duplicate values.\n\n3. `while (head != NULL) { ... }`: Iterate through the list using the `head` pointer.\n\n4. `if (head->next != NULL && head->val == head->next->val) { ... }`: Check if the current node has a next node and if their values are equal, indicating duplicate nodes.\n\n5. `while (head->next != NULL && head->val == head->next->val) { ... }`: Inside the inner loop, skip all consecutive nodes with the same value.\n\n6. `prev->next = head->next;`: Update the `next` pointer of the `prev` node to skip the duplicate nodes.\n\n7. `else { prev = prev->next; }`: If there are no duplicates, move the `prev` pointer to the next node.\n\n8. `head = head->next;`: Move the `head` pointer to the next node.\n\n9. `return dummy->next;`: Return the modified list starting from the next of the dummy node, which effectively skips the original dummy node and provides the head of the modified list.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:**0()**\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:**0(1)**\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n![upvote2.png](https://assets.leetcode.com/users/images/6198d926-527c-42f7-a663-aaf8d62ed44c_1704980133.0159707.png)\n\n\n# Code\n```\nclass Solution {\npublic:\n    ListNode* deleteDuplicates(ListNode* head)\n    {\n        ListNode *dummy=new ListNode(0,head);\n        ListNode *prev=dummy;\n        while(head!=NULL)\n        {\n            if(head->next!=NULL && head->val==head->next->val)\n            {\n                while(head->next!=NULL && head->val==head->next->val)\n                {\n                    head=head->next;\n                }\n            prev->next=head->next;\n            }\n            else\n            {\n                prev=prev->next;\n            }\n        head=head->next;\n        }\n        return dummy->next;    \n    }\n};\n```
['Linked List', 'Two Pointers', 'C++']