```
class Solution {
public:
ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
set<ListNode*> setA,setB;
while(headA||headB)
{
if(headA)
{
setA.insert(headA);
headA = headA->next;
}
if(headB)
{
setB.insert(headB);
headB = headB->next;
}
}
vector<ListNode*> result;
set_intersection(setA.begin(), setA.end(),
setB.begin(), setB.end(),
inserter(result,result.begin()));
if(result.size()==0)
return nullptr;
return result[0];
}
```

};