链表题

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

class Solution {
public:
    /**
     * 
     * @param head ListNode类 
     * @return ListNode类
     */
    ListNode* deleteDuplicates(ListNode* head) {
        // write code here
        if(head == NULL) return NULL;
        ListNode* dummyHead = new ListNode(-1);
        ListNode* p = dummyHead;
        ListNode* tmp = head; //暂时需要判断可能是重复元素的节点
        ListNode* cur = head -> next;
        bool isDuplicated = false;
        while(cur != NULL){
            if(tmp -> val != cur -> val){
                if(!isDuplicated){
                    p -> next = tmp;
                    p = p -> next;
                }
                tmp = cur;
                isDuplicated = false;
            }else isDuplicated = true;
            cur = cur -> next;
        }
        if(!isDuplicated){ //注意点
            p -> next = tmp;
            p = p -> next;
        }
        p -> next = NULL;
        return dummyHead -> next;
    }
};