In this Leetcode Intersection of Two Linked Lists problem solution we have Given the heads of two singly linked-lists headA and headB, return the node at which the two lists intersect. If the two linked lists have no intersection at all, return null.

## Problem solution in Python.

```class Solution:
s1=[]
s2=[]

wow = None
while s1 and s2:

if s1[-1] == s2.pop():
wow=s1.pop()
else:
return wow
return wow
```

## Problem solution in Java.

```public class Solution {

int ACount =0;
int BCount=0;
while(A!=null){
ACount++;
A=A.next;
}

while(B!=null){
BCount++;
B=B.next;
}

int diff= Math.abs(ACount-BCount);
if(ACount>BCount){
while(diff>0){
A=A.next;
diff--;
}
}else{
while(diff>0){
B=B.next;
diff--;
}
}

while(A!=B){
A=A.next;
B=B.next;
}

return A;
}
}
```

## Problem solution in C++.

```ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
while(a != NULL && b != NULL) {
if(a == b) return a;
a = a->next;
b = b->next;
if(a == NULL && b == NULL) return NULL;
if(a == NULL) a = headB;
if(b == NULL) b = headA;
}
return NULL;
}
```

## Problem solution in C.

```struct ListNode *getIntersectionNode(struct ListNode *headA, struct ListNode *headB) {
return NULL;
int countA=0;
int countB=0;
while(tmpA!=NULL || tmpB!=NULL){
if(tmpA!=NULL){countA++;tmpA=tmpA->next;}
if(tmpB!=NULL){countB++;tmpB=tmpB->next;}
}
int diff;

if(countA>=countB){
diff=countA-countB;
while(diff){tmpA=tmpA->next;diff--;}

}
else{
diff=countB-countA;
while(diff){tmpB=tmpB->next;diff--;}
}
while(tmpA!=NULL && tmpB!=NULL){
if(tmpA==tmpB)
return tmpA;
tmpA=tmpA->next;
tmpB=tmpB->next;
}
return NULL;
}
```