my solution is like this: using two pointers, one of them one step at a time. another pointer each take two steps. Suppose the first meet at step ** k**,the length of the Cycle is

**. so..**

*r***2k-k=nr,k=nr**

Now, the distance between the start node of list and the start node of cycle is

**. the distance between the start of list and the first meeting node is**

*s***(the pointer which wake one step at a time waked k steps).the distance between the start node of cycle and the first meeting node is**

*k***, so...**

*m***s=k-m,**

s=nr-m=(n-1)r+(r-m),here we takes n = 1..so, using one pointer start from the start node of list, another pointer start from the first meeting node, all of them wake one step at a time, the first time they meeting each other is the start of the cycle.

s=nr-m=(n-1)r+(r-m),here we takes n = 1

```
ListNode *detectCycle(ListNode *head) {
if (head == NULL || head->next == NULL) return NULL;
ListNode* firstp = head;
ListNode* secondp = head;
bool isCycle = false;
while(firstp != NULL && secondp != NULL) {
firstp = firstp->next;
if (secondp->next == NULL) return NULL;
secondp = secondp->next->next;
if (firstp == secondp) { isCycle = true; break; }
}
if(!isCycle) return NULL;
firstp = head;
while( firstp != secondp) {
firstp = firstp->next;
secondp = secondp->next;
}
return firstp;
}
```