Why the input like {3,2,0,-4} resulted in TLE? The algorithm is pretty like others: 1) first loop to find out whether there is a cycle. 2) reset p to head and another loop to find the beginning of the cycle...

And for {3, 2, 0,-4}, only first iteration is mandatory.

```
public class Solution
{
public ListNode detectCycle(ListNode head)
{
if (head == null || head.next == null)
return null;
ListNode p = head;
ListNode q = head.next.next;
while (p != null && q!= null)
{
if ( p == q)
break;
p = p.next;
q = q.next;
if (q != null)
q = q.next;
}
if (p == null || q == null)
return null;
// must have a cycle
p = head;
while (p != q )
{
p = p.next;
q = q.next;
}
return p;
}
}
```