/**
* 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 *s = head,*e = head;
while(head&&head->next&&head->val == head->next->val)
{
e = head->next;
int val = e->val;
while(e&&e->val == val)
e = e->next;
head = e;
}
if(head == NULL) return NULL;
if(head->next== NULL) return head;
s = head;
while(s->next&&s->next->next)
{
if(s->next->val != s->next->next->val)
s = s->next;
else
{
e = s->next;
int val = e->val;
while(e&&e->val == val)
e=e->next;
s->next = e;
}
}
return head;
}
};
LeetCode 82. Remove Duplicates from Sorted List II
最新推荐文章于 2022-04-03 22:46:44 发布