slow
and fast
to the head of the linked list.fast
is null
or fast.next
is null
:
a. Move slow
one step forward (slow = slow.next
).
b. Move fast
two steps forward (fast = fast.next.next
).slow
will be at the middle node. Return slow
.