1class Solution {2public:3ListNode *deleteDuplicates(ListNode *head) {4ListNode *k = new ListNode();5ListNode *root = k, *cur = head;6while (cur != NULL) {7ListNode *t = cur;8while (t->next != NULL && t->next->val == t->val) t = t->next;9if (t == cur) {10if (root == NULL)11root->val = t->val;12else {13ListNode *p = new ListNode(t->val);14root->next = p;15root = root->next;16}17}18cur = t->next;19}20return k->next;21}22};