From 3fbe4c3573c52f64a093291ffcf3d39d59593c00 Mon Sep 17 00:00:00 2001 From: Ashley Benson Date: Thu, 23 Feb 2023 20:14:00 -0800 Subject: [PATCH] All tests passed --- linked_lists/intersection.py | 10 +++++++++- tests/test_intersection.py | 4 +++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/linked_lists/intersection.py b/linked_lists/intersection.py index f07e2ae..634ff2f 100644 --- a/linked_lists/intersection.py +++ b/linked_lists/intersection.py @@ -11,4 +11,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 + + a, b = headA, headB + if not a or not b: + return None + + while a!=b: + a = headB if not a else a.next + b = headA if not b else b.next + return a \ No newline at end of file diff --git a/tests/test_intersection.py b/tests/test_intersection.py index aa0937e..6b47e45 100644 --- a/tests/test_intersection.py +++ b/tests/test_intersection.py @@ -1,5 +1,7 @@ import pytest -from linked_lists.intersection import * +# from linked_lists.intersection import +from linked_lists.intersection import Node +from linked_lists.intersection import intersection_node def test_will_return_intersection_for_lists_of_same_length():