## Intersection of Two Linked Lists（leetcode160） 原

woshixin

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

For example, the following two linked lists:

```A:          a1 → a2
↘
c1 → c2 → c3
↗
B:     b1 → b2 → b3```

begin to intersect at node c1.

Notes:

• If the two linked lists have no intersection at all, return `null`.
• The linked lists must retain their original structure after the function returns.
• You may assume there are no cycles anywhere in the entire linked structure.
• Your code should preferably run in O(n) time and use only O(1) memory.
```public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
//boundary check
return null;
}

//这么写还是有点趣的，因为查完A list然后接着是 Blist，那么这样就可以不用考虑长度不等啦
while( a != b){
a = a == null? headB : a.next;
b = b == null? headA : b.next;
}

return a;
}

return null;
}

Set<ListNode> set = new HashSet<ListNode>();

while(a!=null) {
a=a.next;
}
while(b!=null)  {
if(set.contains(b)) {
return b;
}
b = b.next;
}
return null;
}```

### woshixin

[LeetCode] Intersection of Two Linked Lists

★ 题目 https://leetcode.com/problems/intersection-of-two-linked-lists/ Write a program to find the node at which the intersection of two singly linked lists begins. For exampl......

u013553529
01/16
0
0
Leetcode 160. Intersection of Two Linked Lists

SnailTyan
10/27
0
0

2016/12/26
2
0
LeetCode 160. Intersection of Two Linked Lists (两链表相交点)

dby_freedom
12/02
0
0

Linked List 链表 141. Linked List Cycle 判断单链表中是否有环 使用到的数据结构：List 使用到的算法技巧：Tow Pointers 辅助指针 这道题目同样也可以用哈希表 160. Intersection of Two L...

Ice_Frog
05/30
0
0

jquery通过id显示隐藏

var \$div3 = \$('#div3'); 显示 \$div3.show(); 隐藏 \$div3.hide();

yan_liu

3
0
《乱世佳人》读书笔记及相关感悟3900字

《乱世佳人》读书笔记及相关感悟3900字： 之前一直听「荔枝」，后来不知怎的转向了「喜马拉雅」，一听就是三年。上班的时候听房产，买房了以后听装修，兴之所至时听旅行，分手后听亲密关系，...

3
0

em_aaron

3
0

3
0

Dubbo是什么? 使用背景 dubbo为什么这么流行, 为什么大家都这么喜欢用dubbo; 通过了解分布式开发了解到, 为适应访问量暴增,业务拆分后, 子应用部署在多台服务器上,而多台服务器通过可以通过d...

4
0