LeetCode题解之Intersection of Two Linked Lists
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的更多相关文章
- [LeetCode 题解]:Intersection of Two Linked Lists
前言 [LeetCode 题解]系列传送门: http://www.cnblogs.com/double-win/category/573499.html 1.题目描述 Suppose an ...
- 【一天一道LeetCode】#160. Intersection of Two Linked Lists
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Write a ...
- 【LeetCode】160. Intersection of Two Linked Lists 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 双指针 栈 日期 题目地址:https://leet ...
- 【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 ...
- 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 ...
- 【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 ...
- (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 ...
- 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 ...
- LeetCode算法题-Intersection of Two Linked Lists(Java实现)
这是悦乐书的第178次更新,第180篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第37题(顺位题号是160).编写程序以找到两个单链表交叉的节点.例如: 以下两个链表: ...
随机推荐
- JDK1.10+scala环境的搭建之windows环境
第一步:安装jdk 1,http://www.oracle.com/technetwork/java/javase/downloads/jdk10-downloads-4416644.html 去找下 ...
- 关于class的签名Signature
举例1: public class Test05<A, B extends java.util.List<String>, C extends InputStream&Ser ...
- 搭建安卓开发环境 hello world andriod
万事开头能嘛.先要搭建开发环境,主要用到java,会java的同学福音啊. 一 相关下载 1.Jdk.(java的开发环境). http://www.oracle.com/technetwork/j ...
- php的数组变量
数组就是存储同一类型的多个变量的 一种特殊的类型 php的数组有两种形态 1.普通类型 eg:$cars = array("Volvo","BMW"," ...
- Java Graphics 图形绘制
Graphics类提供基本绘图方法,Graphics类提供基本的几何图形绘制方法,主要有:画线段.画矩形.画圆.画带颜色的图形.画椭圆.画圆弧.画多边形.画字符串等. 画线段 drawLine pub ...
- 【转】Js获取当前日期时间及其它操作
Js获取当前日期时间及其它操作 原文地址:http://www.cnblogs.com/carekee/articles/1678041.html var myDate = new Date();my ...
- 三种数据库访问——Spring3.2 + Hibernate4.2
前三篇随笔中介绍了 用原生的JDBC访问数据库.一种高效的数据库连接池druid.用Spring的JDBC框架访问数据库. 本文继续介绍第三种数据库访问的解决方案:Spring3.2 + Hibern ...
- VB/C#获取资源Rources
VB.Net: My.Resources.ResourceManager.GetObject("data") C# Properties.Resources.文件名
- Java中Date与String的相互转换
我们在注册网站的时候,往往需要填写个人信息,如姓名,年龄,出生日期等,在页面上的出生日期的值传递到后台的时候是一个字符串,而我们存入数据库的时候确需要一个日期类型,反过来,在页面上显示的时候,需要从数 ...
- 手把手教你写一个java的orm(一)
写之前的说明 其实吧. 这个东西已经写好了,地址在:https://github.com/hjx601496320/JdbcPlus 这系列文章算是我写的过程的总结吧.(恩系列,说明我可能会写好久,╮ ...