/* struct ListNode { int val; struct ListNode *next; ListNode(int x) : val(x), next(NULL) { } };*/ class Solution { public: ListNode* FindFirstCommonNode( ListNode* pHead1, ListNode* pHead2) { ListNode*p=pHead1; unordered_set<ListNode*>hash; while(p) { hash.insert(p); p=p->next; } p=pHead2; while(p) { if(hash.count(p)) { return p; } p=p->next; } return NULL; } };