链表删除重复节点
2019-03-02 本文已影响0人
厂厂哥
/*function ListNode(x){
this.val = x;
this.next = null;
}*/
function deleteDuplication(pHead)
{
// write code here
var a={};
a.next=pHead;
var arr=[pHead.val];
var q=pHead;
var c=q.next;
var n=c.next
while(n!==null){
if(arr.join().indexOf(c.val)==-1){
arr.push(c.val);
var t=n;
q=c;
c=t;
n=t.next;
}else{
var t=n;
c=t;
q.next=c;
n=t.next;
}
}
return a.next;
}
module.exports = {
deleteDuplication : deleteDuplication
};