Finding the intersecting node from two intersecting linked lists

前端 未结 6 1521
旧巷少年郎
旧巷少年郎 2020-11-30 22:19

Suppose there are two singly linked lists both of which intersect at some point and become a single linked list.

The head or start pointers of both the lists are kno

6条回答
  •  野性不改
    2020-11-30 23:09

    If possible, you could add a 'color' field or similar to the nodes. Iterate over one of the lists, coloring the nodes as you go. Then iterate over the second list. As soon as you reach a node that is already colored, you have found the intersection.

提交回复
热议问题