断链、删除、合并,代码如下:

//
// Created by jt on 2020/9/24.
//
class Solution {
public:
    /**
     *
     * @param head ListNode类
     * @return ListNode类
     */
    ListNode* deleteDuplicates(ListNode* head) {
        // write code here
        ListNode dummy(0);
        ListNode *p = &dummy, *q = head;
        while (q) {
            while (q->next && q->next->val == q->val) {
                ListNode *tmp = q;
                q = q->next;
                delete tmp;
            }
            p->next = q;
            p = p->next;
            q = q->next;
        }
        p->next = nullptr;
        return dummy.next;
    }
};