标签:
这是一道关于链表的题,其实关于链表的题都没有什么技巧,就是一堆的指针指来指去,和女朋友这短时间感情不稳定,静不下心来写了,直接看的答案,因为感觉不难,全都是看细心不细心·································
/**
* 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 *pre,*now,*Head;
if(!head||!head->next)return head;
Head=new ListNode(-1);
Head->next=head;
pre=Head;
now=head;
while(now&&now->next)
{
if(now->val == now->next->val)
{
while(now->next && now->val == now->next->val)
{
now=now->next;
}
pre->next=now->next;
now=now->next;
}
else
{
pre=now;
now=now->next;
}
}
head=Head->next;
delete(Head);
return head;
}
};
Remove Duplicates from Sorted List II
标签:
原文地址:http://www.cnblogs.com/qiaozhoulin/p/4775306.html