题解 | #复杂链表的复制#

复杂链表的复制

http://www.nowcoder.com/practice/f836b2c43afc4b35ad6adc41ec941dba

function RandomListNode(x){
    this.label = x;
    this.next = null;
    this.random = null;
}
function Clone(pHead)
{
    // write code here
    if (!pHead) return null;
    let result = new RandomListNode(pHead.label);
    let t = result;
    let p =pHead;
    p.match = result;
    p= p.next;
    while(p){
        let node = new RandomListNode(p.label);
        t.next = node;
        t = node;
        p.match = node;
        p= p.next;
    }
    t.next = null;
    p = pHead;
    while(p){
        if(p.random){
            p.match.random = p.random.match;
        }
        p = p.next
    }
    return result
}
module.exports = {
    Clone : Clone
};
全部评论

相关推荐

但听说转正率很低,我现在有在实习了,好纠结要不要去
熬夜脱发码农:转正率低归低,但是实习的经历你可以拿着,又不是说秋招不准备了
点赞 评论 收藏
分享
06-05 19:46
已编辑
武汉大学 后端
点赞 评论 收藏
分享
程序员饺子:正常 我沟通了200多个 15个要简历 面试2个 全投的成都的小厂。很多看我是27直接不会了😅
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务