From ecacf54998ea451892cbd3df6af02a4b405753c8 Mon Sep 17 00:00:00 2001 From: jlee1414 Date: Thu, 29 Sep 2022 00:06:36 -0700 Subject: [PATCH 1/2] created function to find intersection of two linked list. If the list does not intersect, the fnction will return none --- linked_lists/intersection.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/linked_lists/intersection.py b/linked_lists/intersection.py index f07e2ae..84042ea 100644 --- a/linked_lists/intersection.py +++ b/linked_lists/intersection.py @@ -8,7 +8,12 @@ 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 + while headA is not None: + tempB = headB + while tempB is not None: + if headA == tempB: + return headA + tempB = tempB.next + headA = headA.next + + return None \ No newline at end of file From 9f418286d7472a639bf3e274ca60427af158537a Mon Sep 17 00:00:00 2001 From: jlee1414 Date: Tue, 4 Oct 2022 21:35:33 -0700 Subject: [PATCH 2/2] minor tweaks --- linked_lists/intersection.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/linked_lists/intersection.py b/linked_lists/intersection.py index 84042ea..4c38cab 100644 --- a/linked_lists/intersection.py +++ b/linked_lists/intersection.py @@ -1,6 +1,3 @@ - - - class Node: def __init__(self, value): self.val = value @@ -15,5 +12,4 @@ def intersection_node(headA, headB): return headA tempB = tempB.next headA = headA.next - - return None \ No newline at end of file +