题解 | #两个链表的第一个公共结点#
两个链表的第一个公共结点
https://www.nowcoder.com/practice/6ab1d9a29e88450685099d45c9e31e46
/*很笨的循环全比较 struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { } };*/ class Solution { public: ListNode* FindFirstCommonNode( ListNode* pHead1, ListNode* pHead2) { ListNode* pHead3; while (pHead1!=NULL) { pHead3=pHead2; while (pHead3!=NULL&&pHead3!=pHead1) { pHead3=pHead3->next; } if (pHead3!=NULL) { return pHead3; } pHead1=pHead1->next; } return pHead3; } };