Mid point in a link list in a single traversal?

Viewed 2103

I'm trying to find the point of a singly link list where a loop begins. what I thought of was taking 2 pointers *slow, *fast one moving with twice the speed of other. If the list has a loop then at some point

    5-6-7-8
    |     |
1-2-3-4-7-7

slow=fast

Can there be another elegant solution so that the list is traversed only once?

3 Answers
Related