Here is my accepted answer using C ++.As u can see, i use a O(n) space-complexity.I wonder what the O(1) space-complexity method is.Thanks.

```
class Solution {
public:
ListNode *detectCycle(ListNode *head) {
if (head == NULL)return NULL;
ListNode *fast, *slow;
map<ListNode*, bool> mp;
mp.clear();
fast = slow = head;
int count = 0;
fast = fast->next;
while (fast != NULL){
if (!(count%2)){
mp[slow] = true;
slow = slow -> next;
}
if (mp[fast] == true)return fast;
fast = fast->next;
count ++;
}
return NULL;
}
};
```