标签:
1 class Solution { 2 public: 3 ListNode* deleteDuplication(ListNode* pHead) 4 { 5 if(pHead == NULL || pHead->next == NULL) 6 return pHead; 7 ListNode *head = NULL, *pb = pHead, *pe = pHead->next, *pre = head; 8 while(pb && pe) 9 { 10 while(pe && pb->val == pe->val) 11 { 12 pe = pe->next; 13 if(!pe) 14 { 15 if(pre) 16 pre->next = NULL; 17 return head; 18 } 19 else if(pb->val != pe->val) 20 { 21 pb = pe; 22 pe = pe->next; 23 // if(!pe) 24 // return head; 25 } 26 } 27 if(pre != NULL) 28 { 29 pre->next = pb; 30 pre = pb; 31 pb = pe; 32 if(pe) 33 pe =pe->next; 34 } 35 else 36 { 37 head = pb; 38 pre = head; 39 pb = pe; 40 if(pe) 41 pe = pe->next; 42 43 } 44 45 } 46 return head; 47 } 48 };
标签:
原文地址:http://www.cnblogs.com/daocaorenblog/p/5454454.html