题解 | #两个链表的第一个公共结点#
两个链表的第一个公共结点
https://www.nowcoder.com/practice/6ab1d9a29e88450685099d45c9e31e46
struct ListNode* FindFirstCommonNode(struct ListNode* pHead1, struct ListNode* pHead2 ) {
struct ListNode* t1,*t2;
if(!pHead1 || !pHead2)
{
return NULL;
}
// write code here
t1 = pHead1;
t2 = pHead2;
while (t1) {
t2 = pHead2;
while(t2)
{
if(t1==t2)
{
return t2;
}
t2=t2->next;
}
t1=t1->next;
}
return NULL;
}