```function RandomListNode(x){
this.label = x;
this.next = null;
this.random = null;
}
function Clone(pHead)
{
// write code here
//思路:复制插入节点,赋值random,拆分节点
if(pHead===null){return null}
//复制插入节点
let temp = pHead
while(temp){
let copyNode =new RandomListNode(temp.label)
copyNode.next = temp.next
temp.next = copyNode
temp = temp.next.next
}
//赋值复制节点的random
temp = pHead
while(temp){
if(temp.random){
temp.next.random = temp.random.next //复制节点紧邻原节点,复制节点的random节点也紧邻原节点的random节点
} else{temp.next.random = null}
temp = temp.next.next
}
//拆分节点
let root = pHead.next //取出原链表偶数节点依次赋给新链表的节点
let r = root
temp = pHead.next
while(temp){
if(temp.next===null){break}
temp = temp.next.next//此处需要先判断是否为最后的节点,若没有判断:temp.next为null时,解析null.next报错
r.next = temp
r = r.next
}
//返回新链表头节点
return root
}
module.exports = {
Clone : Clone
};