链表删除重复节点

/*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
};

你可能感兴趣的:(链表删除重复节点)