/**
* 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) {
if(head==NULL||head->next==NULL)
return head;
ListNode*L=new ListNode(0);
ListNode*s=L;
while(head!=NULL&&head->next!=NULL)
{
if(head->val!=head->next->val)
{
L->next=head;
L=L->next;
}
head=head->next;
}
if(head==NULL)
{
L->next=head;
return s->next;
}
if(head->next==NULL)
{
L->next=head;
L=L->next;
L->next=NULL;
return s->next;
}
}
};
83. Remove Duplicates from Sorted List
最新推荐文章于 2024-10-31 19:07:52 发布