Standard C++ Solution
\n\n# Approach\n Describe your approach to solving the problem. \nThe standard way to handle this use case is to use the so-called Sentinel Node. Sentinel nodes
\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThe standard way to handle this use case is to use the so-called Sentinel Node. Sentinel nodes are widely used for trees and linked lists as pseudo-heads, pseudo-tails, etc. They are purely functional and usually don\'t hold any data. Their primary purpose is to standardize the situation to avoid edge case handling.\n\nFor example, let\'s use here pseudo-head with zero value to ensure that the situation "delete the list head" could never happen, and all nodes to delete are "inside" the list.\n\n# Complexity\n- Time complexity: O(N)\n    one linear traversing of the linked list\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n    Because not using any additonal space\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\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\nclass Solution {\npublic:\n    ListNode* deleteDuplicates(ListNode* head) {\n        ListNode* sentinel = new ListNode(0, head);\n        ListNode* prev = sentinel;\n        while(head){\n            if(head->next and head->val == head->next->val){\n                while(head->next and head->val == head->next->val){\n                    head = head->next;\n                }\n                prev->next = head->next;\n            }\n            else{\n                prev = prev->next;\n            }\n            head = head->next; \n        }\n        return sentinel->next;\n    }\n};\n\n```
['C++']