/*
struct ListNode {
int val;
struct ListNode *next;
ListNode(int x) :
val(x), next(NULL) {
}
};
*/
class Solution {
public:
ListNode* deleteDuplication(ListNode* pHead)
{
ListNode* head = new ListNode(0);
ListNode* p = head;
p->next = pHead;
while(p && p->next) {
ListNode* q = p->next;
while(q->next && q->val == q->next->val) q = q->next;
if(p->next == q) p = q;
else p->next = q->next;
}
return head->next;
}
};
【剑指 offer】JZ56 删除链表中重复的结点 C++
最新推荐文章于 2021-01-24 19:46:06 发布