876. Middle of the Linked List

Easy

Given a non-empty, singly linked list with head node head, return a middle node of linked list. If there are two middle nodes, return the second middle node. Note: The number of nodes in the given list will be between 1 and 100.

😇 Solution

class Solution:
    def middleNode(self, head: ListNode) -> ListNode:
        
        slow = fast = head
        while fast and fast.next:
            slow = slow.next
            fast = fast.next.next
        
        return slow

Last updated

Was this helpful?