Share my idea [p.s. no code inside]


  • 0
    S

    if the two have intersection, then they must have the same tail from end.
    like :

    headA=[1,2,3,4,5,6,7,8]

    headB=[2,1,3,9,5,4,6,7,8]

    so the fisrt step is to reverse the linkedlist, then scan from the reversed two util they have different value, like 5 in headA and 4 in headB.

    but i think my idea is a little complex for python doing it.

    wish it could get you some tips. disccusstion is welcomed!


  • 0
    D

    why do that have to have the same tail end?

    a1,a2,a3,c1,c2,a4,a5
    b1,b2,c1,c2,b3,b4

    these intersect on c1,c2 but have different tail ends


  • 0
    S

    the Question is said that:
    "Write a program to find the node at which the intersection of two singly linked lists begins."


  • 0
    I

    I tried a similar approach, however, OJ tell me that you can't modify the structure of link list


  • 0
    S

    you modifyed the structure of list ? no way ... how could it be..
    must somewhere wrong.
    i will give a try then share my code.


  • 0
    J

    I reverse it back at last, and it works on IDE,but oj tell me 'linked structure was modified'


  • 0
    J

    But if so the node c2 will have different next nodes. Is "the same node" in the sense of same object, or only having same value should suffice?


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.