链表没有直接求几个的size
用哈希表把heada存进哈希,在用哈希表的count(b),这个计算b出现几次,没出现就是=0;
cpp
class Solution {
public:
ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
unordered_set<ListNode*> cmp;
ListNode *tmp = headA;
while(tmp){
cmp.insert(tmp);
tmp = tmp->next;
}
tmp = headB;
while(tmp){
if(cmp.count(tmp)){
return tmp;
}
tmp = tmp->next;
}
return NULL;
}
};