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

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

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

import java.util.*;

public class Solution {
    public ListNode FindFirstCommonNode(ListNode pHead1, ListNode pHead2) {
        ListNode p2 = pHead2;
        if (pHead1 == null || pHead2 == null)
            return null;
        while(pHead1 != null){
            while(pHead2 != null){
                if(pHead1 == pHead2)
                    return pHead1;
                pHead2 = pHead2.next;
            }
            pHead1 = pHead1.next;
            pHead2 = p2;
        }
        return null;
    }
}

全部评论

相关推荐

fRank1e:吓得我不敢去外包了,但是目前也只有外包这一个实习,我还要继续去吗
点赞 评论 收藏
分享
鬼迹人途:你去投一投尚游游戏,服务器一面,第一个图算法,做完了给你一个策略题,你给出方案他就提出低概率问题,答不上当场给你挂
点赞 评论 收藏
分享
昨天 18:44
已编辑
中山职业技术学院 Java
投递文远知行等公司7个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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