pNode* findCommonList(pNode* l1, pNode* l2) {
if (!l1 || !l2)
return NULL;
pNode dummy;
pNode* tail = &dummy;
map<int, int> hashTab; // record the node exits
pNode* l = l1;
while(l) {
if (!hashTab.find(l->data)
map.insert(l->data, 1);
l++;
}
while(l2) {
if (hashTab.find(l2->data)) {
pNode* node = new pNode(l2->data);
tail->next = node;
tail = node;
}
l2++;
}
return dummy.next;
}
找两个链表的共同点
最新推荐文章于 2020-07-06 17:38:17 发布