一、题目
二、思路
1、保留重复元素中的一个
2、建立头结点
三、代码
class Solution {
public:
ListNode* deleteDuplicates(ListNode* head) {
if(head==nullptr){
return nullptr;
}
ListNode *node=new ListNode(INT_MIN);
ListNode *cur=node;
cur->next=head;
while(cur->next){
if(cur->next->val==cur->val){
cur->next=cur->next->next;
}
else{
cur=cur->next;
}
}
return node->next;
}
};