Check if two linked lists merge. If so, where?

后端 未结 26 1392
陌清茗
陌清茗 2020-12-07 06:43

This question may be old, but I couldn\'t think of an answer.

Say, there are two lists of different lengths, merging at a point; how do we know wher

26条回答
  •  伪装坚强ぢ
    2020-12-07 07:34

    If editing the linked list is allowed,

    1. Then just make the next node pointers of all the nodes of list 2 as null.
    2. Find the data value of the last node of the list 1. This will give you the intersecting node in single traversal of both the lists, with "no hi fi logic".

提交回复
热议问题