AcWing 3756. 筛选链表
原题链接
简单
作者:
丶123
,
2021-07-21 15:24:00
,
所有人可见
,
阅读 208
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* filterList(ListNode* head) {
int a[10010] = {0};
auto p = head;
auto pre = head;
while(p != NULL)
{
int data = abs(p->val);
if(a[data] == 1)
{
pre->next = p->next;
auto tmp = p;
p = p->next;
delete(tmp);
}else
{
a[data] = 1;
pre = p;
p = p->next;
}
}
return head;
}
};