class Solution {
public:
bool hasCycle(ListNode *head)
{
map<ListNode*, int> mp;
while(head != NULL)
{
if(0 == mp[head])
{
mp[head] = 1;
}
else
{
return true;
}
head = head->next;
}
return false;
}
};