这是个比较简单的题目,关键要细心
/**
* 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) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(head==NULL) return NULL;
ListNode* del=head,*res=head;
while(del!=NULL){
ListNode *pre=del,*cur=del->next;
while(cur!=NULL){
if(cur->val==del->val){
pre->next=cur->next;
ListNode *tmp=cur;
delete tmp;
cur=pre->next;
}else{
pre=pre->next;
cur=cur->next;
}
}
del=del->next;
}
return res;
}
};