diff --git a/linked_lists/intersection.py b/linked_lists/intersection.py index f07e2ae..6ba6efd 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_node(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