diff --git a/linked_lists/intersection.py b/linked_lists/intersection.py index f07e2ae..952b2f4 100644 --- a/linked_lists/intersection.py +++ b/linked_lists/intersection.py @@ -11,4 +11,24 @@ 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 + + #linked_list_a: 3 -> 4 -> 5 -> 6 -> 7 + # linked_list_b: 1 -> 2 -> 5 -> 6 -> 7 + + if not headA or not headB: + return None + + current_a = headA + current_b = headB + + while current_b: + while current_a: + if current_a == current_b: + return current_a + current_a = current_a.next + + current_a = headA + current_b = current_b.next + + return None + \ No newline at end of file