Back to DashboardView Problem Source
Middle of the LinkedList
EasyProblem Statement
Given the head of a Singly LinkedList, write a method to return the middle node of the LinkedList.
If the total number of nodes in the LinkedList is even, return the second middle node.
Examples
Example 1:
- Input:
head = [1,2,3,4,5] - Output:
3
Approach 1 Slow Fast Pointers:
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public ListNode middleNode(ListNode head) {
var slow = head;
var fast = head;
while (fast != null && fast.next != null) {
slow = slow.next;
fast = fast.next.next;
}
return slow;
}
}
Status
Solved
Complexity
Time
O(n)Space
O(1)Tags
Linked ListSlow Fast Pointers
Date
2026-02-09