This question is a little interesting. I know the answer and find it. It's easy to do. At first, I thought about how to use another pointer after the meeting, and then push it out after satisfying the relationship. In fact, this is not necessary. It is a very simple mathematical relationship. Let me draw a picture to illustrate it.
S1 represents the length before the linked list enters the ring. a represents the length of the pointer in the ring when two pointers encounter each other. S2 represents the circumference of the ring, then, according to the conditions, the distance between the two-step pointer is twice the distance between the two-step pointer. We get the formula:
(S1 + a) * 2 = S1 + S2 +
Simplified to get <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + forward + vLSjrLu31tDKo8/forward + forward/forward + YWO0 + forward + CjxwcmUgY2xhc3M9 "brush: java;"> class Solution {public: ListNode * detectCycle) {if (! Head |! Head-> next) return NULL; ListNode * a = head-> next, * B = head-> next; while (! = B & a & B-> next) {a = a-> next; B = B-> next;} if (! = B) return NULL; a = head; while (! = B) {a = a-> next; B = B-> next;} return ;}};