Problem
Given the head of a non-empty linked list, return the middle node. If there are two middle nodes (an even count), return the second one. Aim for a single pass.
The tests show the list from the node you return onwards.
Example 1
- Input
- 1
- Output
- 2 -> 3 -> 4 -> 5 → 3 -> 4 -> 5
Example 2
- Input
- 1
- Output
- 2 -> 3 -> 4 -> 5 -> 6 → 4 -> 5 -> 6
Constraints
1 <= number of nodes <= 1001 <= Node.val <= 100