✅☑️ Easy C++ solution || Linked list + Two Pointer || Best Solution(Optimized).
Intuition\n Describe your first thoughts on how to solve this problem. \nWe can solve this question using Linklist + Two Pointer.\n\n# Approach\n Describe your 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe can solve this question using Linklist + Two Pointer.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe can easily understand the approache by seeing the code which is easy to understand with comments.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nTime Complexity :O(N), because we are traversing over the elements exactly one. Thus the time complexity is linear.\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nSpace Complexity : O(1), because we have used constant elements. Thus the space complexity is constant.\n\n# Code\n```\n/**\n * Definition for singly-linked list.\n * struct ListNode {\n *     int val;\n *     ListNode *next;\n *     ListNode() : val(0), next(nullptr) {}\n *     ListNode(int x) : val(x), next(nullptr) {}\n *     ListNode(int x, ListNode *next) : val(x), next(next) {}\n * };\n */\n\n\n/*\n\n    Time Complexity :O(N), because we are traversing over the elements exactly one. Thus the time complexity is\n    linear.\n\n    Space Complexity : O(1), because we have used constant elements. Thus the space complexity is constant.\n\n    Using Linklist + Two Pointer.\n\n*/\n\n\n/********************************************* First Code *********************************************/\n\nclass Solution {\npublic:\n    ListNode* deleteDuplicates(ListNode* head) {\n        if(head == NULL || head->next == NULL){\n            return head;\n        }\n        ListNode* curr = head;\n        ListNode* prev = NULL;\n        while(curr != NULL && curr->next != NULL){\n            if(curr->val == curr->next->val){\n                while(curr->next != NULL && curr->val == curr->next->val){\n                    curr = curr->next;\n                }\n                if(prev == NULL){\n                    head = curr->next;\n                }\n                else{\n                    prev->next = curr->next;\n                }\n                curr = curr->next;\n            }\n            else{\n                prev = curr;\n                curr = curr->next;\n            }\n        }\n        return head;\n    }\n};\n\n\n\n\n\n\n/********************************************* Second Code *********************************************/\n\nclass Solution {\npublic:\n    ListNode* deleteDuplicates(ListNode* head) {\n        if(head == NULL || head->next == NULL){\n            return head;\n        }\n        ListNode* curr = head;\n        ListNode* dummyHead = new ListNode(-1);\n        ListNode* dummyTail = dummyHead;\n        while(curr != NULL && curr->next != NULL){\n            if(curr->val == curr->next->val){\n                while(curr->next != NULL && curr->val == curr->next->val){\n                    curr = curr->next;\n                }\n                dummyTail->next = curr->next;\n                curr = curr->next;\n            }\n            else{\n                dummyTail->next = curr;\n                dummyTail = curr;\n                curr = curr->next;\n            }\n        }\n        return dummyHead->next;\n    }\n};\n\n\n\n\n\n\n/********************************************* Third Code *********************************************/\n\nclass Solution {\npublic:\n    ListNode* deleteDuplicates(ListNode* head) {\n        if(head == NULL || head->next == NULL){\n            return head;\n        }\n        ListNode* curr = head;\n        ListNode* dummyHead = new ListNode(-1);\n        ListNode* dummyTail = dummyHead;\n        dummyTail->next = curr;\n        while(curr != NULL && curr->next != NULL){\n            if(curr->val == curr->next->val){\n                while(curr->next != NULL && curr->val == curr->next->val){\n                    curr = curr->next;\n                }\n                dummyTail->next = curr->next;\n                curr = curr->next;\n            }\n            else{\n                dummyTail = curr;\n                curr = curr->next;\n            }\n        }\n        return dummyHead->next;\n    }\n};\n```
['Linked List', 'Two Pointers', 'C++']