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