The idea is to move the fast pointer twice as quickly as the slow pointer so the distance between them increases by 1 at each step.
1while fast is not None and fast.next is not None:
2 fast = fast.next.next
3 slow = slow.nextThe idea is to move the fast pointer twice as quickly as the slow pointer so the distance between them increases by 1 at each step.
1while fast is not None and fast.next is not None:
2 fast = fast.next.next
3 slow = slow.next