/** * 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