/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode() : val(0), next(nullptr) {}
* ListNode(int x) : val(x), next(nullptr) {}
* ListNode(int x, ListNode *next) : val(x), next(next) {}
* };
*/
class Solution {
public:
ListNode* deleteDuplicates(ListNode* head) {
if(!head)
{
return head;
}//初始条件判断,不成立的话根本不用进行下一步操作
ListNode*current=head;
while(current->next!=NULL)
{
if(current->next->val==current->val)
{
current->next=current->next->next;
}//注意这里,不用建立临时指针保留当前值
else
current=current->next;
}
return head;
}
};