27/100. Intersection of Two Linked Lists
查找两个单独链表开始相交的节点。
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相关推荐
- [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 ...
- 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 ...
- [Swift]LeetCode160. 相交链表 | Intersection of Two Linked Lists
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★ ➤微信公众号:山青咏芝(shanqingyongzhi) ➤博客园地址:山青咏芝(https://www.cnblog ...
- Intersection of Two Linked Lists 解答
Question Write a program to find the node at which the intersection of two singly linked lists begin ...
- 【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 ...
- 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. Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...
- 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 ...
最新文章
- Git学习系列之一些常用的Git命令收录更新ing
- 一文读懂微服务架构的重构策略
- 『前端干货篇』:你不知道的Stylus
- 五十、微信小程序云开发中的云数据库
- QTP简单框架(6)之脚本编写实例
- 学习笔记~~~~~TreeMap
- 执行Hive语句报错:FAILED: Error in metadata: javax.jdo.JDOFatalDataStoreException: Access denied for user '
- 【开发者成长】Vue.js 中有哪些性能陷阱
- php统计字数指定位置,php实现的统计字数函数定义与使用示例
- 位运算(、|、^、~、>>、<<)
- centos7永久修改ip地址
- 数据结构实验报告:顺序表基本操作的实现
- 贝恩分类法(行业集中度)
- 使用imageIO获取和修改图片的exif信息
- FTP文件传输协议与部署,包括Linux系统、Windows系统和H3C路由交换设备部署
- 【CF #781 Div2】A-C
- 弘辽科技:刘强东下“重手”
- 学习Web前端到就业,掌握好这3点,事半功倍!
- eclipse导出Jar包包含第三方jar包和图片资源
- 修改注册表恢复IE设置(转)