> For the complete documentation index, see [llms.txt](https://jenhsuan.gitbook.io/algorithm/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jenhsuan.gitbook.io/algorithm/leetcode/160.-intersection-of-two-linked-lists.md).

# 160. Intersection of Two Linked Lists

## 1.問題

* 返回開始重複的node

![](/files/-LJDVxSpZbqXHz_ZONym)

## 2.想法

* 用map紀錄s出現過的node, 再看看t是否有出現相同的node

## 3.程式碼

```
/**
 * 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_map<ListNode*, int> m;
        ListNode *head = headA;
        while (head)
        {
            m[head] = 1;
            head = head->next;
        }
        
         head = headB;
         while (head)
         {
            if (m.find(head) != m.end())
            {
                return head;
            }
            head = head->next;
         }
        return NULL;
        
    }
};
```

## 4.Performance

![](/files/-LJDWuK7HK_ZmmY3yURD)
