Detailed Explanation || How to Think about the Ques || 100%
Intuition\nTo solve this problem, we can use a dummy node and two pointers, current and previous. The dummy node serves as the head of the result linked list an
# Intuition\nTo solve this problem, we can use a dummy node and two pointers, current and previous. The dummy node serves as the head of the result linked list and helps us handle the case where the original head node needs to be removed. The current pointer moves through the linked list, checking for duplicates, and the previous pointer follows behind it, keeping track of the last distinct node.\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n- We first create a dummy node with a value of 0 and set its next pointer to the original head node. We also initialize the prev and curr pointers to the dummy node and the head node, respectively.\n- We then iterate through the linked list using the curr pointer, checking for duplicates with the curr.next node. If we find duplicates, we keep moving the curr pointer until we find the last duplicate node. We then update the prev.next pointer to point to the node after the last duplicate node.\n- If we don\'t find duplicates, we simply update the prev pointer to the curr node and move the curr pointer to its next node\n- After iterating through the entire linked list, we return the next pointer of the dummy node, which points to the head of the resulting linked list.\n<!-- Describe your approach to solving the problem. -->\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\nclass Solution {\npublic:\n    ListNode* deleteDuplicates(ListNode* head) {\n\n        if(head == NULL || head->next == NULL) return head;\n\n        ListNode* dummy = new ListNode(0);\n        dummy->next = head;\n        ListNode* curr = head;\n        ListNode* prev = dummy;\n\n        while(curr != NULL){\n            if(curr->next != NULL && curr->val == curr->next->val){\n                while(curr->next != NULL && curr->val == curr->next->val){\n                    curr= curr->next;\n                }\n                prev->next = curr->next;\n            }\n            else{\n                prev = curr;\n            }\n            curr = curr->next;\n        }\n        return dummy->next;\n    }\n};\n```\n\n![7abc56.jpg](https://assets.leetcode.com/users/images/53a2ee22-0977-4b5c-9768-f81d45e59bc2_1677219527.1926677.jpeg)\n\n
['C++']