From a24788e64d7c54de135feecc5f3d004c1bbb0a9b Mon Sep 17 00:00:00 2001 From: Veronica Osei Date: Thu, 20 Oct 2022 14:48:24 -0500 Subject: [PATCH] Tests passing --- linked_lists/intersection.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/linked_lists/intersection.py b/linked_lists/intersection.py index f07e2ae..df5b1c2 100644 --- a/linked_lists/intersection.py +++ b/linked_lists/intersection.py @@ -1,6 +1,9 @@ +from queue import Empty + + class Node: def __init__(self, value): self.val = value @@ -8,7 +11,17 @@ def __init__(self, value): 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 headA is None or headB is None: # check to see if either heads are empty + return None + seen = [] + while headA: + seen.append(headA) #append the first item + headA = headA.next # assign the headA to next so the next item can get appended + while headB: # iterate through the second LL + if headB in seen: # check to see if the first item is in the seen list + return headB # return if it is + headB = headB.next # if not go to the next item in the LL + return None # if nothing is found return None + + + \ No newline at end of file