Odd length list
Input
head = [1,2,3,4,5]
Output
3
The middle of [1,2,3,4,5] is 3.
Full lesson preview
Find the middle node of a singly linked list using the fast and slow pointer technique.
Problem statement
Task
Examples
Input
head = [1,2,3,4,5]
Output
3
The middle of [1,2,3,4,5] is 3.
Input
head = [1,2,3,4]
Output
3
For even length, return the second middle (3).
Input format
Output format
Constraints
Samples
Input
[10, 20, 30, 40, 50]
Output
30
The middle node's value is 30.