`
class Solution {
public:
ListNode findFirstCommonNode(ListNode headA, ListNode *headB) {
map[HTML_REMOVED] phash;
int n =0;
for(auto p = headA; p ; p = p->next)
{
phash[p] = n;
n++;
}
for(auto p = headB; p ; p = p->next)
{
if(phash.find(p) != phash.end())
return p;
}
return nullptr;
}
};`
第一次遍历,建立hash,
第二次遍历,查找表