/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* deleteDuplicates(ListNode* head) {
ListNode* tmp = new ListNode(0);
ListNode* curr = head;
ListNode* pre = tmp;
pre->next = curr;
while (curr && curr->next) {
if (curr->val == curr->next->val) {
pre->next = curr->next;
curr->next = NULL;
curr = pre->next;
} else {
pre = curr;
curr = curr->next;
}
}
return tmp->next;
}
};