eg:        a1 → a2
   ↘
c1 → c2 → c3 或者直接a1 → b1
          ↗ 
    b1 → b2 → b3
求公共链表c1. 常规的指针分裂法,复制法,偏移法。
 public class Solution {
public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
if(headA==null||headB==null) return null;
int lengthA=0;
int lengthB=0;
ListNode currentA=headA;
ListNode currentB=headB;
while(currentA.next!=null)
{
currentA=currentA.next;
lengthA++;
}
while(currentB.next!=null)
{
currentB=currentB.next;
lengthB++;
}
ListNode fast=lengthA>lengthB?headA:headB;
ListNode slow=lengthA>lengthB?headB:headA;
for(int i=0;i<Math.abs(lengthA-lengthB);i++)
{
fast=fast.next;
} while(fast!=null)
{
if(fast==slow)
return fast;
else
{
fast=fast.next;
slow=slow.next;
}
}
return null;
}
}

Intersection of Two Linked Lists(java)的更多相关文章

  1. LeetCode: Intersection of Two Linked Lists 解题报告

    Intersection of Two Linked Lists Write a program to find the node at which the intersection of two s ...

  2. [LintCode] Intersection of Two Linked Lists 求两个链表的交点

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

  3. [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 ...

  4. 2016.5.24——Intersection of Two Linked Lists

    Intersection of Two Linked Lists 本题收获: 1.链表的输入输出 2.交叉链表:这个链表可以有交叉点,只要前一个节点的的->next相同即可. 题目:Inters ...

  5. [LeetCode]160.Intersection of Two Linked Lists(2个链表的公共节点)

    Intersection of Two Linked Lists Write a program to find the node at which the intersection of two s ...

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

    160. Intersection of Two Linked Lists[easy] Write a program to find the node at which the intersecti ...

  7. LeetCode_160. Intersection of Two Linked Lists

    160. Intersection of Two Linked Lists Easy Write a program to find the node at which the intersectio ...

  8. LeetCode--LinkedList--160. Intersection of Two Linked Lists(Easy)

    160. Intersection of Two Linked Lists(Easy) 题目地址https://leetcode.com/problems/intersection-of-two-li ...

  9. Java for 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 ...

随机推荐

  1. undefined和null的区别

    在javascript中undefined和null几乎是没有区别的 undefined==null;//true;   区别:   null是一个表示“无”的对象,转为数值为0:或者说没有对象,此处 ...

  2. 我对 javascript 闭包的理解

    学js的学到闭包,但是理解不深. 后来看了一下这篇文章: 地址:http://leepiao.blog.163.com/blog/static/4850313020112835355917/ 内容如下 ...

  3. python os模块文件相关

    使用前 import os导入模块   os模块: os.sep     可以取代操作系统特定的路径分割符 os.linesep  字符串给出当前平台使用的行终止符.例如,Windows使用'\r\n ...

  4. FFMPEG视音频解码【一】

    多媒体的时代,得多了解点编解码的技术才行,而ffmpeg为我们提供了一系列多媒体编解码的接口,如何用好这些接口达到自己所需要的目的,这也是一门重要的学问. 要是了解得不够,总是会遇到一堆又一堆问题:网 ...

  5. git configuration

    git的配置文件由section名和变量名组成: [user] name = abc emial = example.com []里面的user就是section名,section只能由字母,数字,- ...

  6. iis10,php 5.2 isapi 扩展

    1.添加isapi映射模块: 2.设置独立应用程序池,注意php版本,5.2,要设置程序池32位. 64位下配置IIS+PHP出现404.17错误的解决办法

  7. python运维开发(二十三)---tornado框架

    内容目录: 路由系统 模板引擎 cookie 加密cookie 自定义api 自定义session 自定义form表单验证 异步非阻塞 web聊天室实例 路由系统 路由系统其实就是 url 和 类 的 ...

  8. Python学习笔记三,数组list和tuple

    list也就是列表的意思,可以存储一组数据集合,比如classmates=['zhangsan','lisi','123']每个数据用单引号包裹,逗号隔开.

  9. linux的一点一滴---open

    open函数用于打开和创建一个文件. 所需头文件: #include<sys/types.h> #include <sys/stat.h> #include <fcntl ...

  10. C语言--关键字 typedef

    一.typedef 1.基本使用 1> typedef 在基本数据类型中的使用 typedef int MyInt; // 相当于给 int 起了一个别名 typedef MyInt MyInt ...