struct HashTable {
struct ListNode *tmp;
UT_hash_handle hh;
};
struct ListNode *getIntersectionNode(struct ListNode *headA, struct ListNode *headB) {
struct ListNode *pA = headA, *pB = headB;
struct HashTable *ht = NULL;
struct ListNode *retval;
while (pA) {
struct HashTable *temp = (struct HashTable *)malloc(sizeof(struct HashTable));
temp->tmp = pA;
HASH_ADD(hh, ht, tmp, sizeof(struct HashTable *), temp);
pA = pA->next;
}
while (pB) {
struct HashTable *temp = NULL;
HASH_FIND(hh, ht, &pB, sizeof(struct HashTable *), temp);
if (temp) {
retval = pB;
break;
}
pB = pB->next;
}
struct HashTable *iter, *temp;
HASH_ITER(hh, ht, iter, temp) {
HASH_DEL(ht, iter);
free(iter);
}
return retval;
}