/**
* 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||head->next==NULL) {
return head;
}
ListNode* phead=head;
while(phead->next) {
if (phead->val==phead->next->val) {
ListNode* p =phead->next;
phead->next=p->next;
p->next=NULL;
delete p;
p=0;
} else {
phead=phead->next;
}
}
return head;
}
};
* 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||head->next==NULL) {
return head;
}
ListNode* phead=head;
while(phead->next) {
if (phead->val==phead->next->val) {
ListNode* p =phead->next;
phead->next=p->next;
p->next=NULL;
delete p;
p=0;
} else {
phead=phead->next;
}
}
return head;
}
};