Simple cpp soln O(n)


#1

ListNode* Solution::getIntersectionNode(ListNode* A, ListNode* B) {

set<ListNode*> s;

while(A!=NULL)
{
    s.insert(A);
    A=A->next;
}
while(B!=NULL)
{
    if(s.find(B)!=s.end())
       return B;
    B=B->next;
}
return NULL;

}strong text


#2

But you are taking extra O(n) space here!