Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions linked_lists/intersection.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@



class Node:
def __init__(self, value):
self.val = value
Expand All @@ -11,4 +8,12 @@ def intersection_node(headA, headB):
""" Will return the node at which the two lists intersect.
If the two linked lists have no intersection at all, return None.
"""
pass
if not headA or not headB:
return None

nodeA = headA
nodeB = headB
while nodeA is not nodeB:
nodeA = headB if nodeA is None else nodeA.next
nodeB = headA if nodeB is None else nodeB.next
return nodeA