here is the question of linked list for cycle detection
i am getting wrong answer in some of the test cases. can you tell my mistake
here is the code
ListNode *detectCycle(ListNode *head) {
if(head==NULL)
{
return NULL;
}
ListNode* slow=head;
ListNode* fast=head;
while(fast!=NULL && fast->next!=NULL)
{
fast=fast->next->next;
slow=slow->next;
if(fast==slow)
{
break;
}
}
return slow->next;
}
};