diff --git a/linked_lists/intersection.py b/linked_lists/intersection.py index f07e2ae..996ee59 100644 --- a/linked_lists/intersection.py +++ b/linked_lists/intersection.py @@ -1,14 +1,22 @@ - - class Node: - def __init__(self, value): - self.val = value - self.next = None + def __init__(self, value, next_node=None): + self.value = value + self.next = next_node 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 headA is None or headB is None: + return None + +# Use current values for the pointers: + pointer_a, pointer_b = headA, headB +# Use a while loop that + while pointer_a != pointer_b: + pointer_a = headB if pointer_a is None else pointer_a.next + pointer_b = headA if pointer_b is None else pointer_b.next + + return pointer_a diff --git a/linked_lists/requirements.txt b/linked_lists/requirements.txt new file mode 100644 index 0000000..e69de29