Problem
You get the head of a linked list with n nodes. Delete the middle node, the one at 0-based index n // 2 (round down), and return the head of the changed list. With an even count that is the second of the two middle nodes. If the list has only one node, deleting it leaves an empty list.
Example 1
- Input
- 1
- Output
- 3 -> 4 -> 7 -> 1 -> 2 -> 6 → 1 -> 3 -> 4 -> 1 -> 2 -> 6
- Why
- index 3 removed
Example 2
- Input
- 1
- Output
- 2 -> 3 -> 4 → 1 -> 2 -> 4
- Why
- index 2 removed
Example 3
- Input
- 2
- Output
- 1 → 2
Return None (null in TypeScript) when nothing is left.
Constraints
1 <= number of nodes <= 10^51 <= Node.val <= 10^5