classSolution{public:boolhasCycle(ListNode*head){// IMPORTANT: Please reset any member data you declared, as
// the same Solution instance will be reused for each test case.
ListNode*step1=head;ListNode*step2=head;while(true){if(step1==NULL){returnfalse;}step1=step1->next;if(step2==NULL||step2->next==NULL){returnfalse;}step2=step2->next->next;if(step1==step2){returntrue;}}}};