what is the error in this code for the leetcode problem.
leetcode-https://leetcode.com/problems/linked-list-cycle/
ide->https://ide.codingblocks.com/s/204106
Linked list cycle -leetcode
@mikkyimran
You have to increment fast pointer twice and slow pointer once for slow pointer, fast pointer to work.
i have incremented fast pointer before the while loop so it stays always one step ahead of slow. will that not work?
Assume the cycle length is of 4, slow moves one step forward then fast moves one step forward. Slow cant catch the fast pointer
fast is one step head before the loop and in the loop both are incremented. i am getting confused in my code also fast in one step head of slow
Fast will always be one step ahead of slow.
that’s what I am saying, in my code also fast is ahead.
But cycle is detected when slow is equal to fast. This condition will never happen.