Middle of the Linked List

Given the head of a singly linked list, return the middle node of the linked list. If there are two middle nodes, return the second middle node.

Constraints

  • The number of nodes in the list is in the range [1, 100].
  • 1 <= Node.val <= 100
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 middleOfTheLinkedList(self, head: ListNode) -> ListNode:

Console

Click Run to execute sample tests.