查找两个单独链表开始相交的节点。

p1从链表A的头节点开始走,p2从链表B的头节点开始走,当它们走到当前链表的尾节点时,从另一链表的头节点开始走(p1走链表B,p2走链表A)。
这样其实当它们走到相交的节点时,正好走过的路径长度是一样的。

# Definition for singly-linked list.
# class ListNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.next = Noneclass Solution(object):def getIntersectionNode(self, headA, headB):""":type head1, head1: ListNode:rtype: ListNode"""if not headA or not headB:return Nonep1 = headAp2 = headBwhile p1 != p2:p1 = p1.next if p1 else headBp2 = p2.next if p2 else headAreturn p1

27/100. Intersection of Two Linked Lists相关推荐

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

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

  2. LeetCode(160): Intersection of Two Linked Lists

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

  3. [Swift]LeetCode160. 相交链表 | Intersection of Two Linked Lists

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ ➤微信公众号:山青咏芝(shanqingyongzhi) ➤博客园地址:山青咏芝(https://www.cnblog ...

  4. Intersection of Two Linked Lists 解答

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

  5. 【leetcode】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. 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 ...

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

  8. leetcode. 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. 160. Intersection of Two Linked Lists(剑指Offer-两个链表的第一个公共结点)

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

最新文章

  1. Git学习系列之一些常用的Git命令收录更新ing
  2. 一文读懂微服务架构的重构策略
  3. 『前端干货篇』:你不知道的Stylus
  4. 五十、微信小程序云开发中的云数据库
  5. QTP简单框架(6)之脚本编写实例
  6. 学习笔记~~~~~TreeMap
  7. 执行Hive语句报错:FAILED: Error in metadata: javax.jdo.JDOFatalDataStoreException: Access denied for user '
  8. 【开发者成长】Vue.js 中有哪些性能陷阱
  9. php统计字数指定位置,php实现的统计字数函数定义与使用示例
  10. 位运算(、|、^、~、>>、<<)
  11. centos7永久修改ip地址
  12. 数据结构实验报告:顺序表基本操作的实现
  13. 贝恩分类法(行业集中度)
  14. 使用imageIO获取和修改图片的exif信息
  15. FTP文件传输协议与部署,包括Linux系统、Windows系统和H3C路由交换设备部署
  16. 【CF #781 Div2】A-C
  17. 弘辽科技:刘强东下“重手”
  18. 学习Web前端到就业,掌握好这3点,事半功倍!
  19. eclipse导出Jar包包含第三方jar包和图片资源
  20. 修改注册表恢复IE设置(转)

热门文章

  1. matlab激光散斑散射半径测量,激光散斑测量2011412225741
  2. 网络电缆 计算机电缆,计算机电缆的技术参数
  3. 参数php_干净的PHP代码-函数参数
  4. 看看 JDK 8 给我们带来什么
  5. Java Bag模型模拟
  6. 【php内核与扩展开发系列】PHP生命周期---启动、终止与模式
  7. clamav程序的研究总结
  8. websocket学习笔记
  9. 数据结构之二分插入排序------java实现
  10. 学习python、数据结构等很多的博客