/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
unordered_map<ListNode*, int> m;
ListNode *head = headA;
while (head)
{
m[head] = 1;
head = head->next;
}
head = headB;
while (head)
{
if (m.find(head) != m.end())
{
return head;
}
head = head->next;
}
return NULL;
}
};