题解 | #两个链表的第一个公共结点#

两个链表的第一个公共结点

https://www.nowcoder.com/practice/6ab1d9a29e88450685099d45c9e31e46

/*function ListNode(x){
    this.val = x;
    this.next = null;
}*/
function FindFirstCommonNode(pHead1, pHead2)
{
    if(pHead1 === null || pHead2 === null) return null
    let p1 = pHead1
    let p2 = pHead2
    while(p1 != p2) {
        p1 = p1?p1.next : pHead2;
        p2 = p2?p2.next : pHead1;
    }
    return p1
}
module.exports = {
    FindFirstCommonNode : FindFirstCommonNode
};

全部评论

相关推荐

fRank1e:吓得我不敢去外包了,但是目前也只有外包这一个实习,我还要继续去吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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