/**
* 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 *p=head;
if(head==NULL)
return head;
while(head->next!=NULL){
if(head->val==head->next->val){
if(head->next->next!=NULL){
head->next=head->next->next;}
if(head->next->next==NULL&&head->val==head->next->val){
head->next=NULL;
return p;
}
}
else//!!!!!!!!!!!!!!!之前这里出问题了
head=head->next;
}
return p;
}
};
不能每次都递进一个指针,否则1->1->1->1这种情况会错!