From 71cb654db20c0c2d677bd708419466c70982b267 Mon Sep 17 00:00:00 2001 From: Theresa Davis Date: Thu, 3 Nov 2022 05:43:51 -0700 Subject: [PATCH 1/2] First Commit --- linked_lists/intersection.py | 39 +++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/linked_lists/intersection.py b/linked_lists/intersection.py index f07e2ae..516391a 100644 --- a/linked_lists/intersection.py +++ b/linked_lists/intersection.py @@ -2,13 +2,42 @@ class Node: - def __init__(self, value): + def __init__(self, value,): self.val = value self.next = None -def intersection_node(headA, headB): - """ Will return the node at which the two lists intersect. + def intersection(headA, headB): + + current_headA = headA + while current_headA is not None: + current_headB = headB + while current_headB is not None: + if current_headA == current_headB: + return current_headA + else: + current_headB = current_headB.next + current_headA = current_headA.next + return None + + + """ 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 + """ + + + + + + + + + + + + + + + + + \ No newline at end of file From 3bb4f3242581f7eef1d424534f2b2a387cfa28d4 Mon Sep 17 00:00:00 2001 From: Theresa Davis Date: Thu, 3 Nov 2022 06:05:22 -0700 Subject: [PATCH 2/2] Updated function name --- linked_lists/intersection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linked_lists/intersection.py b/linked_lists/intersection.py index 516391a..6ba6efd 100644 --- a/linked_lists/intersection.py +++ b/linked_lists/intersection.py @@ -7,7 +7,7 @@ def __init__(self, value,): self.next = None - def intersection(headA, headB): + def intersection_node(headA, headB): current_headA = headA while current_headA is not None: