AcWing 29. 删除链表中重复的节点
原题链接
中等
作者:
Zh1995
,
2019-08-11 08:29:20
,
所有人可见
,
阅读 744
//利用桶的思想去重
class Solution {
public ListNode deleteDuplication(ListNode head) {
int arr[]=new int[100];
ListNode point=head;
while(point!=null)
{
arr[point.val]++;
point=point.next;
}
point=head;
ListNode newHead=new ListNode(100000);
ListNode p=newHead;
while(point!=null)
{
if(arr[point.val]==1)
{
ListNode cur=new ListNode(point.val);
p.next=cur;
p=p.next;
}
point=point.next;
}
newHead=newHead.next;
return newHead;
}
}