/**
 * struct ListNode {
 *	int val;
 *	struct ListNode *next;
 * };
 */

class Solution {
public:
    /**
     * 
     * @param head ListNode类 
     * @return ListNode类
     */
    ListNode* deleteDuplicates(ListNode* head) {
        // write code here
        ListNode* node = new ListNode(-1);
        ListNode* pre = node;
        
        node->next = head;
        while (head && head->next)
        {
            if (head->val != head->next->val)
            {
                pre = head;
                head = head->next;
            }
            else
            {
                int n = head->val;
                while(head && head->val == n){
                    head = head->next;
                }
            }
            pre->next = head;
        }
        pre->next = head;
        return node->next;
    }
};