mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
18 lines
461 B
C
18 lines
461 B
C
|
struct ListNode *getIntersectionNode(struct ListNode *headA, struct ListNode *headB) {
|
||
|
struct ListNode *cur1 = headA, *cur2 = headB;
|
||
|
if(cur1 == NULL || cur2 == NULL)
|
||
|
return NULL;
|
||
|
while (cur1 && cur2 && cur1 != cur2) {
|
||
|
cur1 = cur1 -> next;
|
||
|
cur2 = cur2 -> next;
|
||
|
if (cur1 == cur2)
|
||
|
return cur1;
|
||
|
if(!cur1)
|
||
|
cur1 = headB;
|
||
|
if(!cur2)
|
||
|
cur2 = headA;
|
||
|
}
|
||
|
return cur1;
|
||
|
|
||
|
}
|