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;
}
}

最新文章

  1. css文件 引用后不起作用
  2. 【JavaScript】操作Canvas画图
  3. Spring+SpringMvc+Mybatis框架集成搭建教程四(项目部署及测试)
  4. 《On Lisp》第四章第三节图4.6中的rmapcar函数中展现的apply陷阱
  5. 修改ubuntu DNS的步骤/wget url报错: unable to resolve host address的解决方法
  6. zabbix服务器监控suse系统教程
  7. 怎样开启SQL数据库服务
  8. 利用Multipeer Connectivity框架进行WiFi传输-b
  9. mysql时间int日期转换
  10. 后台返回data直接在页面转换
  11. 【思路解析】discuz 帖子设置封面 setthreadcover 表pre_forum_threadimage
  12. CentOS安装常用软件
  13. SERVLET API 中 forward() 与 redirect()的区别?
  14. 一个开源Delphi分类组件推荐网页
  15. TCP closing a connection
  16. Ubuntu16.04部署python2和python3共存的Jupyter Notebook
  17. 利用 Blob 处理 node 层返回的二进制文件流字符串并下载文件
  18. Oracle数据库启动出现ORA-27101错误之ORA-19815处理方式及数据备份
  19. I/O模型系列之一:Linux I/O模型基本概念
  20. WINFROM窗体实现圆角

热门文章

  1. HDU 1084 - ACM
  2. C# 对类中的保护成员进行写操作(邀请大家拍砖)
  3. Retrieving the COM class factory for component with CLSID XX failed due to the following error: 80070005 拒绝访问。
  4. Proud Merchants(POJ 3466 01背包+排序)
  5. Taurus.MVC
  6. usb mass storage之旅
  7. WinForm 鼠标进入移开窗体事件,因子控件导致的误触发
  8. C语言的本质(38)——makefile之变量
  9. 非常棒的Java REST服务器栈
  10. 携程SQL面试题忘大牛解答解决思路