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

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

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

/*
1. 主要思路就是如何让两个链表长度相等,利用 两链表长度加起来相等原理,实现,太妙了
function ListNode(x){
    this.val = x;
    this.next = null;
}*/
function FindFirstCommonNode(pHead1, pHead2)
{
    // write code here
    let ta = pHead1
    let tb = pHead2
    while(ta !== tb){
        ta = ta ? ta.next : pHead2
        tb = tb ? tb.next : pHead1
    }
    return ta
}
module.exports = {
    FindFirstCommonNode : FindFirstCommonNode
};

全部评论

相关推荐

许愿ssp的咸鱼很不想泡池子:import python as pyhton
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务