Hey! I've found a solution with O(n) time complexity and O(1) space complexity. My method is very simple with the follow steps:

- Find a ring point via "fast and slow running" method.if there isn't a node like that,then return NULL;
- Cut the ring at the ring point found before,making the cycle link list like two rails with different start points jioning together.
- Make the two "rails" the same length.
- search the two "rails" the same time,and compare the two nodes,if they are equal,return one which is the answer .

my code:

```
ListNode *detectCycle(ListNode *head) {
ListNode * p1,* p2,* p3;
int m = 0;
if(!head||!head->next)
return NULL;
p1 = head->next;
p2 = head->next->next;
while(true) //find a ring node using "fast and slow" method
{
if(p1 == p2) //if find the ring node,cut the ring at this node.
{ // It like two rails with different start point jioning together.
p2 = p1->next; //make p2 the front node of the cut node,in other word the second rail's start point.
//head is the first rail's start point.
p1->next = NULL; //make the cute node's next NULL.
p1 = head;
p3 = p1;
while(p3) //this code's purpose is to make the two rails the same length.
{
p3 = p3->next;
m++;
}
p3 = p2;
while(p3)
{
p3 = p3->next;
m--;
}
if(m>=0)
while(m--)
p1 = p1->next;
else
while(m++)
p2 = p2->next;
while(p1&&p2) //search the two rails in the same time;
{
if(p1 == p2) //the first equal node is the begin node of the cycle
return p1; //return the node.
p1 = p1->next;
p2 = p2->next;
}
}
if(p1->next)
p1 = p1->next;
else
return NULL;
if(p2->next&&p2->next->next)
p2 = p2->next->next;
else
return NULL;
}
return NULL;
}
```