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.
1for fast != nil && fast.next != nil {
2 slow = slow.next
3 fast = fast.next.next
4}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.
1for fast != nil && fast.next != nil {
2 slow = slow.next
3 fast = fast.next.next
4}