diff --git a/linked_lists/intersection.py b/linked_lists/intersection.py index f07e2ae..32122c2 100644 --- a/linked_lists/intersection.py +++ b/linked_lists/intersection.py @@ -1,6 +1,3 @@ - - - class Node: def __init__(self, value): self.val = value @@ -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 \ No newline at end of file + 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