Back to Month
MEDIUM 15 Jun 2026

2095. Delete the Middle Node of a Linked List

</> Solution

class Solution {
    public ListNode deleteMiddle(ListNode head) {
       // If there is only one node
        if (head == null || head.next == null) {
            return null;
        }

        ListNode slow = head;
        ListNode fast = head;
        ListNode prev = null;

        // Find the middle node
        while (fast != null && fast.next != null) {
            prev = slow;
            slow = slow.next;
            fast = fast.next.next;
        }

        // Delete the middle node
        prev.next = slow.next;

        return head; 
    }
}

TIME COMPLEXITY

O(n)

SPACE COMPLEXITY

O(1)

TOPICS

Linked List Two Pointers