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).编写程序以找到两个单链表交叉的节点.例如: 以下两个链表: ...
随机推荐
- 再学Java 之 形参个数可变函数
自Java 5后,Java允许定义形参个数可变的方法,从而允许运行过程中,为方法指定不确定个数的形参. 其定义方法的格式如下: void function_name ( type ... variab ...
- PreparedStatement插入values
public interface PreparedStatementextends Statement 表示预编译的 SQL 语句的对象. SQL 语句被预编译并存储在 PreparedStateme ...
- 【数组】Search for a Range
题目: Given a sorted array of integers, find the starting and ending position of a given target value. ...
- Gen中的switch分析及lookupswitch与tableswitch指令
int chooseNear(int i) { switch (i) { case 0: return 0; case 1: return 1; case 2: return 2; default: ...
- Java性能调优:利用JMC进行性能分析
JMC, 即Java任务控制(Java Mission Control)是从Java7(7u40)和 Java8 的商业版本包括一项新的监控和控制特性. JMC 程序 (JDK_HOME\bin目录下 ...
- SpringBoot入门 (一) HelloWorld
一 什么是springboot springboot是一个全新的框架,它设计的目的简化spring项目的初始环境的搭建和开发,主要有以下几个特点: 1.简化初始配置 ,可与主流框架集成: 2.内置Se ...
- SpringBoot源码分析之SpringBoot的启动过程
SpringBoot源码分析之SpringBoot的启动过程 发表于 2017-04-30 | 分类于 springboot | 0 Comments | 阅读次数 SpringB ...
- Linux下常用的3种软件安装方式
一:Linux源码安装 1.解压源码包文件 源码包通常会使用tar工具归档然后使用gunzip或bzip2进行压缩,后缀格式会分别为.tar.gz与.tar.bz2,分别的解压方式: ...
- 关于发布程序之后js文件存在缓存问题
把js文件加上版本号即可解决 如: <script src="../Static/js/Contract/ContractRateEdit.js?t=20181210"> ...
- 哪个类可用于处理 Unicode?
A. InputStreanReader的构造函数: InputStreamReader(InputStream in) 创建一个使用默认字符集的 InputStreamReader ...