leetcode刷题思路总结_intersection two linked lists解题思路:
利用 STL的set集合 ——set集合元素集合唯一,不存在重复元素。
1.将A链表元素地址依次存入自定义set集合。
2.遍历B链表与set集合进行匹配,放回第一个匹配到的结点
`class Solution {
public:
std::set<ListNode*> myset;
ListNode* FindFirstCommonNode( ListNode* headA, ListNode* headB) {

    while(headA)
    {
        myset.insert(headA);
        headA=headA->next;
    }
    
    while(headB)
    {
        
        if(myset.find(headB)!=myset.end()) return headB;
        
        headB=headB->next;
        
    }
    
    return NULL;
}

};
`

相关文章:

  • 2022-02-22
  • 2021-06-07
  • 2021-05-19
  • 2021-12-11
  • 2021-08-16
  • 2021-12-24
猜你喜欢
  • 2022-12-23
  • 2021-11-28
  • 2022-12-23
  • 2021-06-26
  • 2021-11-29
  • 2021-08-05
  • 2021-06-15
相关资源
相似解决方案