题意
判断两个链表是否存在相同的一段链表,如果有就返回该相同的链条,没有返回null
能做到效率为O(n) 空间复杂度为O(1)
我的思路
和判断循环的链表一样使用HashSet,需要开辟O(n)的空间,以及O(n+m)的效率
我的代码
1 | public class Solution { |
大神代码
1 | public class Solution { |
不知道说什么了,引用一下别人的评论吧
Clever, the two iterations will both run for listA.length + listB.length and will reach the intersection point at the same time after switching the pointer.
This is a very clever and easy to read solution. You da man!
1 |
|