TC: O(n), SC: O(1) | C++
\nclass Solution {\npublic:\n    ListNode* deleteDuplicates(ListNode* head) {\n        if(head==NULL || head->next==NULL)\n            return head;\n        \n 
```\nclass Solution {\npublic:\n    ListNode* deleteDuplicates(ListNode* head) {\n        if(head==NULL || head->next==NULL)\n            return head;\n        \n        ListNode* dummy = new ListNode(0, head);\n        ListNode* temp=head;\n        ListNode* prev=dummy;\n        \n        while(temp!=NULL){\n            if(temp->next!=NULL && temp->val == temp->next->val){\n                while(temp->next!=NULL && temp->val == temp->next->val)\n                    temp=temp->next;\n                prev->next=temp->next;\n            }\n            else if(prev->next!=NULL)\n                prev=prev->next;\n            temp=temp->next;      \n        }\n        return dummy->next;\n    }\n};\n```
['Linked List']