题解 | #两个链表的第一个公共结点#
两个链表的第一个公共结点
https://www.nowcoder.com/practice/6ab1d9a29e88450685099d45c9e31e46
/* public class ListNode { public int val; public ListNode next; public ListNode (int x) { val = x; } }*/ class Solution { public ListNode FindFirstCommonNode(ListNode pHead1, ListNode pHead2) { // write code here ListNode t1 = pHead1; ListNode t2 = pHead2; while (t2 != null) { t1 = pHead1; while (t1 != null) { if (t1 == t2) { return t1; } else { t1 = t1.next; } } t2 = t2.next; } return null; } }