Find Middle of the Linked List - aloalgo

Find Middle of the Linked List

Easy

You are given the head of a singly linked list.

Your task is to find and return the middle node of this linked list. If the list contains an even number of nodes, you must return the second of the two middle nodes.

Example 1

Input
1 → 2 → 3 → null
Output
2 → 3 → null
Explanation:

The list has 3 nodes. The middle node is the one with value 2.

Example 2

Input
1 → 2 → 3 → 4 → null
Output
3 → 4 → null
Explanation:

The list has 4 nodes. The middle nodes are 2 and 3, so we return the second one, which has value 3.

Loading...
Input
1 → 2 → 3 → null
Output
2 → 3 → null

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!