From 27cca63bdba200b467c6645384d051a07be064a2 Mon Sep 17 00:00:00 2001 From: Shannon B <89764051+eggoweggo@users.noreply.github.com> Date: Sat, 14 Jan 2023 13:32:40 -0700 Subject: [PATCH] finished linked list --- 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..32122c2 100644 --- a/linked_lists/intersection.py +++ b/linked_lists/intersection.py @@ -1,6 +1,3 @@ - - - class Node: def __init__(self, value): self.val = value @@ -11,4 +8,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 + if not headA or not headB: + return None + + nodeA = headA + nodeB = headB + while nodeA is not nodeB: + nodeA = headB if nodeA is None else nodeA.next + nodeB = headA if nodeB is None else nodeB.next + return nodeA