Middle of Linked List
5/29/2022 / 1 minute to read / Tags: solution
Middle of Linked list
In the list 1->2->3->4->5
, S
and F
point to 1. What are S
and F
when S
moves by 1 element and F
moves by 2 elements?
S
is slow pointer andF
is fast pointer
Will S
travel half the distance of F
at any given point?
- Yes, since
F
is twice as fast asS
Will S
be at middle of list when F
is at the end?
- Yes
Do we have our base case and reduction case?
- Yes we do
← Back to notes