/**
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
class Solution {
public:
/**
*
* @param head ListNode类
* @return ListNode类
*/
ListNode* deleteDuplicates(ListNode* head) {
// write code here
if(head==NULL||head->next==NULL)
return head;
ListNode*pre=head,*cur=head->next;
while(cur){
if(cur->val!=pre->val){
pre=cur;
cur=cur->next;
}
else{
pre->next=cur->next;
cur=pre->next;
}
}
return head;
}
};
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
class Solution {
public:
/**
*
* @param head ListNode类
* @return ListNode类
*/
ListNode* deleteDuplicates(ListNode* head) {
// write code here
if(head==NULL||head->next==NULL)
return head;
ListNode*pre=head,*cur=head->next;
while(cur){
if(cur->val!=pre->val){
pre=cur;
cur=cur->next;
}
else{
pre->next=cur->next;
cur=pre->next;
}
}
return head;
}
};