From 1a09853c2e3f6b9983b42da8fec2f685474a107b Mon Sep 17 00:00:00 2001 From: verasazonova Date: Sat, 10 Dec 2022 16:08:00 -0800 Subject: [PATCH] VeraSa C17 --- linked_lists/intersection.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/linked_lists/intersection.py b/linked_lists/intersection.py index f07e2ae..4c03aa0 100644 --- a/linked_lists/intersection.py +++ b/linked_lists/intersection.py @@ -11,4 +11,19 @@ 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 + + a = headA + b = headB + + while a != b: + if a: + a = a.next + else: + a = headB + if b: + b = b.next + else: + b = headA + return a \ No newline at end of file