标签:style blog http color os io art ar
Corner cases!
class Solution { public: ListNode *deleteDuplicates(ListNode *head) { if (!head) return head; if (!head->next) return head; ListNode dum(-1); dum.next = head; ListNode *pPre = &dum; ListNode *p1 = head; int cnt = 0; int last = std::numeric_limits<int>::max(); while (p1) { // A new one? if (p1->val != last) { if (cnt > 1) { pPre->next = p1; last = p1->val; } else { last = p1->val; while (pPre->next != p1) pPre = pPre->next; } cnt = 1; } else { cnt++; } p1 = p1->next; } if (cnt > 1) { if (pPre == &dum) return NULL; else { pPre->next = NULL; } }; return dum.next; } };
LeetCode "Remove Duplicates from Sorted List II",布布扣,bubuko.com
LeetCode "Remove Duplicates from Sorted List II"
标签:style blog http color os io art ar
原文地址:http://www.cnblogs.com/tonix/p/3888013.html