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

复杂链表的复制

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
};
全部评论

相关推荐

我是没经验的毕业生,这啥情况啊会不会是hr在刷kpi
JamesGosli...:字节boss属于是群发了,我都快入职字节了,其他部门还在和我boss打招呼
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

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