LeetCode Remove Duplicates from Sorted List

来源:互联网 发布:吊装计算软件 编辑:程序博客网 时间:2024/06/05 23:58

nothing to it.

ListNode *deleteDuplicates(ListNode *head) {if(head==NULL||head->next==NULL)return head;ListNode *p=head,*s=NULL;ListNode *q=head->next;while(q!=NULL){if (p->val!=q->val){p = q;q = q->next;}else{s = q;q = q->next;p->next = s->next;delete s;}}return head;}


0 0
原创粉丝点击