Given a linked list, determine if it has a cycle in it.
简单的快慢指针.
bool hasCycle(ListNode *head)
{
if(head == NULL || head->next == NULL) return false;
ListNode * fast = head;
ListNode * slow = head;
while(fast != NULL && fast->next != NULL){
fast = fast->next->next;
slow = slow->next;
if(fast == slow) return true;
}
return false;
}