Bootcamps
Masterclasses
Menu
Courses
Account
Login / Sign Up

Find Middle of Linked List

Easy Acceptance 87% Points 20

You are given the head of a singly linked list. Your task is to find and return the middle node of the linked list. If the linked list contains an even number of nodes, return the second middle node.

Examples
Example 1

Example 1

Input: head = [1,2,3,4,5]

Output: 3

Explanation: The linked list contains 5 nodes. The middle node is 3.

Example 2

Example 2

Input: head = [1,2,3,4,5,6]

Output: 4

Explanation: The linked list contains 6 nodes. There are two middle nodes (3 and 4), so the second middle node, 4, is returned.

Example 3

Example 3

Input: head = [10]

Output: 10

Explanation: The linked list contains only one node, so it is the middle node.

Constraints
  • 1 = Number of nodes = 105
  • -10? = Node.data = 10?
Topics
Linked List
Companies
Microsoft
Added 25 Jul 2026 87% acceptance
Ln 1, Col 1Sign in to save your code
1 2 3 4 5
3