标签:blog io 2014 log on c amp ad res
觉着自己写的比看到的答案精简,分享一下:
class Solution { public: ListNode *deleteDuplicates(ListNode *head) { if(head == NULL) return NULL; ListNode res(-1); ListNode* pre = &res; pre->next = head; bool flag = true; while(head != NULL){ if(head->next == NULL || head->val != head->next->val){ if(!flag) pre->next = head->next; else pre = pre->next; flag = true; }else flag = false; head = head->next; } return res.next; } };
【leetcode】Remove Duplicates from Sorted List II-很精简
标签:blog io 2014 log on c amp ad res
原文地址:http://blog.csdn.net/cx351864995/article/details/39126881