/* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { } }; */ class Solution { public: ListNode* deleteDuplication(ListNode* pHead) { if (!pHead || !pHead->next) return pHead ; ListNode* prev = new ListNode(0), * cur = pHead, * next = pHead->next; prev->next = cur ; ListNode* node = prev ; bool nee_dele = false ; while (next != nullptr) { if (cur->val == next->val) { next = next->next ; nee_dele = true ; } else if ((cur->val != next->val) && (nee_dele)) { prev->next = next ; cur = next ; next = next->next ; nee_dele = false ; } else { prev->next = cur ; prev = prev->next ; cur = cur->next ; next = next->next ; } } if (nee_dele) prev->next = next ; return node->next ; }; };