标签:new 开始 val color ted amp lse names ica
题意略:
思路:先造一个点它与所有点的值都不同,那么只要后面两个点的值相同就开始判断后面是不是也相同,最后将相同的拆下来就可以了。
#include<iostream> #include<cstdio> using namespace std; struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {} }; class Solution { public: ListNode *deleteDuplicates(ListNode *head) { ListNode *pre = new ListNode(666); pre->next = head; ListNode *p = pre, *q; while (p->next&&p->next->next){ if (p->next->val == p->next->next->val){ q = p->next->next->next; while (q&&q->val == p->next->val)q = q->next; p->next->next = q; } else{ p = p->next; } } return pre->next; } };
remove-duplicates-from-sorted-list (删除)
标签:new 开始 val color ted amp lse names ica
原文地址:https://www.cnblogs.com/ALINGMAOMAO/p/9995870.html