Ordered to delete the list the same elements ii

Today wrote a title list ordered to delete the list of the same element that he is indeed very weak in terms of design algorithm, algorithms have no idea began to write, a positive result is very bad, there is a recent problem is mainly brush, the main question is to brush and a lot of good people mature reference code.

 

 

This question is very simple topic, difficulty in thinking and details of the above

After the idea is to point to all previous nodes with the same number of st, pointer p to implement traversal to find all the same node, a node with st point after the same node.

class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head) {
        if(head==NULL) return head;
         ListNode *dummy=new ListNode(-1),*p=dummy,*st=NULL;   //dummy指针方便操作,便于比较head和head->next;
         dummy->next=head;
         int t=0;
         while(p->next&&p->next->next){
             if(p->next->val==p->next->next->val){
                 if(t==0)  st=p;                                
                 T = . 1 ; 
                 p = p-> Next;}
              the else  IF (T) { 
             T = 0 ; 
             ST -> Next = p-> next-> Next; 
             p = ST;} // Note that at this time the pointer p pointing
              the else 
             P = p-> Next; 
         } 
         IF (p-> next-> Next == NULL && T) ST-> Next = NULL;
          return dummy-> Next; 
    } 
}; 

there are several other methods, look tomorrow.

 

Guess you like

Origin www.cnblogs.com/aaamax/p/12556220.html