Skip to content

Commit a25911b

Browse files
committed
Intersection
1 parent 1959fda commit a25911b

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

linked-lists/intersection.py

+3-13
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
"""
2-
Write a program to find the node at which the intersection of two singly linked lists begins.
3-
For example, the following two linked lists:
4-
A: a1 → a2
5-
6-
c1 → c2 → c3
7-
8-
B: b1 → b2 → b3
9-
begin to intersect at node c1.
10-
Notes:
11-
If the two linked lists have no intersection at all, return null.
12-
The linked lists must retain their original structure after the function returns.
13-
You may assume there are no cycles anywhere in the entire linked structure.
14-
Your code should preferably run in O(n) time and use only O(1) memory.
2+
Given two singly linked lists, determine if the two lists intersect. Return the intersecting node. Note that the intersection
3+
is defined based on reference, not value. That is, if the kth node of the first linked list is the exact same node (by reference)
4+
as the jth node of the second linked list, then they are intersecting.
155
"""
166
def getIntersectionNode(headA, headB):
177
if headA == None or headB == None:

0 commit comments

Comments
 (0)