Delete the Middle Node of a Linked List

You are given the head of a linked list. Delete the middle node and return the head of the modified linked list. The middle node of a linked list of size n is the floor(n / 2)th node from the start using 0-based indexing.

Constraints

  • The number of nodes in the list is in the range [1, 10^5].
  • 1 <= Node.val <= 10^5
Saving… · 9 lines
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next

class Solution:
def deleteMiddle(self, head: ListNode) -> ListNode:

Console

Click Run to execute sample tests.