struct ListNode *getIntersectionNode(struct ListNode *headA, struct ListNode *headB)
{
struct ListNode *posA = headA;
struct ListNode *posB = headB;
if (!headA || !headB)
return NULL;
int count = 0;
while (posA != posB) {
posA = posA ? posA->next : headB;
posB = posB ? posB->next : headA;
if (count > 2) //防止两节点无相交节点无限循环
return NULL;
if (posA == headB || posB == headA)
count++;
}
return posA;
}