/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* deleteDuplication(ListNode* head) {
auto bh = new ListNode(-1);
bh->next = head;
auto from=bh;
/*
if(from->next->next=to)from=from->next;
else from->next=to;
}
*/
while (from->next) {
auto to = from->next;
while (to && from->next->val == to->val) to = to->next;
if (from->next->next == to) from = from->next;
else from->next = to;
}
return bh->next;
}
};
acwing 29. 删除链表中重复的节点
最新推荐文章于 2021-12-19 21:37:23 发布