Problem statement

https://binarysearch.com/problems/Central-Linked-List/

Solution

Equal to Leetcode 0876 Middle of the Linked List

Complexity

It is O(n) for time and O(1) for space.

Code

class Solution:
    def solve(self, head):
        slow = head
        fast = head

        while fast and fast.next:
            slow = slow.next
            fast = fast.next.next
        return slow.val