class Solution {
public:
bool hasCycle(ListNode *head) {
if(!head) return false;
ListNode *p1 = head, *p2 = head->next;
while(p1 && p2){
if(p1 == p2)
return true;
p1 = p1->next;
p2 = p2->next;
if(p2)
p2 = p2->next;
}
return false;
}
};
141. Linked List Cycle

