Here is my code:

```
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode *checkCircle(ListNode *h)
{
if (h->next==NULL) return NULL;
if (h->next==h) return h;
ListNode *tmp=h->next;
h->next=h;
return checkCircle(tmp);
}
ListNode *detectCycle(ListNode *head) {
if (head==NULL) return NULL;
return checkCircle(head);
}
};
```

It will change the next to point to itself, and the program will write node when it finds the node which next points to itself. Please help.