/**
 * struct ListNode {
 *	int val;
 *	struct ListNode *next;
 *	ListNode(int x) : val(x), next(nullptr) {}
 * };
 */
class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head) {
        // write code here
        if(!head) return head;
        ListNode* left = head;
        ListNode* right;
        while(left)
        {
            right = left->next;
            while(right && right->val == left->val)
            {
                right = right->next;
            }
            left->next = right;
            left = right;
        }
        return head;
    }
};