[Leetcode] 82. Remove duplicates from Sorted List II

Source: Internet
Author: User

/** * Definition for singly-linked list. * struct ListNode {* int val; * ListNode *next; * ListNode (int x): Val (x), Next (NULL) {} *}; */class Solution {//on_my_ownpublic:listnode* deleteduplicates (listnode* head) {listnode *ret=new ListNode (0); The final returned pointer ListNode *ret1=ret;//represents the RET to be linked to the node's pointer listnode *pre=head;//the first node of each repeating group ListNode *cur=hea d;//the last node of each repeating group bool FIRST=TRUE;//1 represents the first time, and 0 means that it is not the first time (cur) {while (Cur->next!=null && Amp            Cur->val==cur->next->val) {cur=cur->next; }//exit cur should point to the last element of the repeating group if (cur->next==null) {} if (pre==cur) {//Description duplicate                    Group does not repeat if (first) {ret->next=cur;                    Ret1=cur;                First=false;                    } else{ret1->next=cur;                Ret1=cur; } PRE=CUR->next;            cur=cur->next;                        } else{//indicates that the repeating group repeats if (cur->next==null) {if (first) {                    ret->next=null;                    } else{ret1->next=null;                 } return ret->next;                } pre=cur->next;            cur=cur->next;    }} return ret->next; }};

  

[Leetcode] 82. Remove duplicates from Sorted List II

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.