/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {
unordered_set<ListNode*>store;
ListNode*t=headA;
while(t)
{
store.insert(t);
t=t->next;
}
t=headB;
while(t)
{
if(store.count(t))
{
return t;
}
t=t->next;
}
return NULL;
}
};
LeetCode 160
最新推荐文章于 2024-11-01 18:51:26 发布