剑指 Offer 52. 两个链表的第一个公共节点 - 力扣(LeetCode)
类似题:LeetCode第 160 题:相交链表(C++)_zj-博客
class Solution {
public:
ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
ListNode *node1 = headA, *node2 = headB;
while(node1 != node2){
node1 = node1 == NULL ? headB : node1->next;
node2 = node2 == NULL ? headA : node2->next;
//cout << node1->val << " " << node2->val << endl;
}
return node1;
}
};