From 4eeb89554360457ce033ae1c8f3c759a81f7d766 Mon Sep 17 00:00:00 2001 From: Poppy Meng Date: Sun, 8 Jan 2023 21:27:09 -0800 Subject: [PATCH] all tests passed --- linked_lists/intersection.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/linked_lists/intersection.py b/linked_lists/intersection.py index f07e2ae..e926efc 100644 --- a/linked_lists/intersection.py +++ b/linked_lists/intersection.py @@ -11,4 +11,11 @@ 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 + p1, p2 = headA, headB + while p1.val!= p2.val: + p1 = p1.next if p1.next else headB + p2 = p2.next if p2.next else headA + + return p1 \ No newline at end of file