1、题目描述

2、问题分析

使用unordered_set 将链表A中的节点地址全部插入,然后使用链表B中的每个节点在A中查找。

3、代码

 ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) {

         if( headA == NULL || headB == NULL )
return NULL;
ListNode* pa = headA;
ListNode* pb = headB;
unordered_set<ListNode*> s;
while( pa != NULL )
{
s.insert(pa);
pa = pa->next;
} while( pb != NULL )
{
if( s.find( pb ) != s.end() )
return pb;
pb = pb->next;
}
return NULL;
}

LeetCode题解之Intersection of Two Linked Lists的更多相关文章

  1. [LeetCode 题解]:Intersection of Two Linked Lists

    前言   [LeetCode 题解]系列传送门:  http://www.cnblogs.com/double-win/category/573499.html   1.题目描述 Suppose an ...

  2. 【一天一道LeetCode】#160. Intersection of Two Linked Lists

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Write a ...

  3. 【LeetCode】160. Intersection of Two Linked Lists 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双指针 栈 日期 题目地址:https://leet ...

  4. 【LeetCode 160】Intersection of Two Linked Lists

    Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...

  5. LeetCode OJ 160. Intersection of Two Linked Lists

    Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...

  6. 【LeetCode】160. Intersection of Two Linked Lists

    题目: Write a program to find the node at which the intersection of two singly linked lists begins. Fo ...

  7. (LeetCode 160)Intersection of Two Linked Lists

    Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...

  8. LeetCode OJ:Intersection of Two Linked Lists(两个链表的插入)

    Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...

  9. LeetCode算法题-Intersection of Two Linked Lists(Java实现)

    这是悦乐书的第178次更新,第180篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第37题(顺位题号是160).编写程序以找到两个单链表交叉的节点.例如: 以下两个链表: ...

随机推荐

  1. MySQl中的\g和\G

    1. \g 在MySQL的sql语句后加上\g,效果等同于加上定界符,一般默认的定界符是分号; 2. \G 在MySQL的sql语句后加上\G,表示将查询结果进行按列打印,可以使每个字段打印到单独的行 ...

  2. rack简介

    什么是rack rack是对ruby的Net::HTTP进行封装了的包,使用rack能够方便的新建一个简单的web应用. what is rack Rack describes itself as f ...

  3. 【树】Kth Smallest Element in a BST(递归)

    题目: Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. ...

  4. python上安装requests

    首先需要配置好python的环境变量. 测试是否成功配置,进入命令行,输入python. 如下图为配置成功. 去第三方库的网站下载安装包,解压在python的安装目录 ,下载地址:https://py ...

  5. javac的泛型

    ?:在实例化对象的时候,不确定泛型参数的具体类型时,可以使用通配符进行对象定义. (1)?表示通配符,通配符 与 T 的区别 T:作用于模板上,用于将数据类型进行参数化,不能用于实例化对象. publ ...

  6. echart 饼图数据为0不显示或者太小显示其他的解决办法

    饼图数据为0或者太小显示如下,不美观 解决办法: 为0的去掉,小于0.005的累加起来 方法 function getsData(_rowData){ var rowData=JSON.parse(J ...

  7. 爬虫实战(二) 51job移动端数据采集

        在上一篇51job职位信息的爬取中,对岗位信息div下各式各样杂乱的标签,简单的Xpath效果不佳,加上string()函数后,也不尽如人意.因此这次我们跳过桌面web端,选择移动端进行爬取. ...

  8. 使用Xshell和Xftfp部署简单的项目

    最近本人偶尔接触到该如何部署项目,朋友要求截图,趁此之际,简单总结一下,以供大家分享,更希望各位大神指点,大家相互学习,有问题的勿喷. 1.使用环境:win 7+MyEclipse 2014 + to ...

  9. HTML自己整理

    1.margin:0 auto 表示什么意思?? margin后面如果只有两个参数的话,第一个表示top和bottom,第二个表示left和right因为0 auto,表示上下边界为0,左右则根据宽度 ...

  10. 在LaTeX中配置西夏文字体与环境

    目录 1 配置字族 2 粗体.斜体设定 3 文本编辑器的字体设定(以Sublime Text为例) 4 附录:一些字体的下载源 警告:这篇文章的部分内容需要西夏文字体才能正常显示.若您需要安装,可参考 ...