C版,不使用缓存区
typedef struct ListNode ListNode;
// 1 1 2 3
struct ListNode* removeDuplicateNodes(struct ListNode* head){
if(head==NULL||head->next==NULL){
return head;
}
ListNode *cur=head;
ListNode *pre=NULL;
ListNode *next=NULL;
while(cur) {
pre=cur;
next=cur->next;
while(next){
if(cur->val==next->val) {
pre->next=next->next;
}else{
pre=next;
}
next=next->next;
}
cur=cur->next;
}
return head;
}