Linked List Cycle II


  • 1

    Click here to see the full article post


  • 0
    J

    It would be easier to understand if you just use h as a, C - h as b, thus F = C - h.
    Pointer 2 starting at intersection ends up at the entrance when slides F steps because h + F = h + C - h = C


  • 0
    P

    perfect guide for me.
    thx for writing this article.


  • 1
    W

    F=b + (n-1)(a+b) n>=1 so they while meet at 0


  • 0
    W

    I don't think this solution is faithfulness enough. The F should be equals to nC+b, (n>=0)rather than b, since F may be very large, but b may be very small.
    But the method still works well.


  • 0
    K

    It is mentioned here that "Because F=b, pointers starting at nodes h and 0 will traverse the same number of nodes before meeting". Instead, should it be like this "pointers starting at nodes h and -F will ...". Hope you noticed that ptr1 starts at -F instead of 0.


Log in to reply
 

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