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

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

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

/*function ListNode(x){
    this.val = x;
    this.next = null;
}*/
/*
{1,2,3},{4,5},{6,7}
{6,7}

{1},{2,3},{}
{}
}*/
function FindFirstCommonNode(pHead1, pHead2) {
    // write code here
    while (pHead1 || pHead2) {
        if (pHead1) {
            if (pHead1.flag) {
                return pHead1;
            }
            pHead1.flag = 1;
            pHead1 = pHead1.next;
        }

        if (pHead2) {
            if (pHead2.flag) {
                return pHead2;
            }
            pHead2.flag = 1;
            pHead2 = pHead2.next;
        }
    }
    return null;
}
module.exports = {
    FindFirstCommonNode: FindFirstCommonNode,
};

全部评论

相关推荐

白火同学:大二有这水平很牛了,可以适当对关键信息加粗一点,比如关键技术、性能指标之类的。
点赞 评论 收藏
分享
码农索隆:7*24,随时待命,这是去🇷🇺打仗去了啊
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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