Loading content...
Given the head of a singly linked list, your task is to locate and return the center node of the list.
A singly linked list is a linear data structure where each element (node) contains a value and a reference (pointer) to the next node in the sequence. The center node is defined as the node that occupies the middle position when the list is traversed from the head to the tail.
Important: When the linked list contains an even number of nodes, there are technically two center positions. In such cases, you must return the second of the two center nodes (the one that appears later in the sequence).
The return value should be the center node itself, along with all subsequent nodes that follow it in the original list structure. This means you are effectively returning the "second half" of the list starting from the center node.
head = [1,2,3,4,5][3,4,5]The linked list has 5 nodes. The center node is at position 3 (1-indexed), which contains the value 3. We return this node along with all nodes that follow it: [3,4,5].
head = [1,2,3,4,5,6][4,5,6]The linked list has 6 nodes, which is an even count. The two center positions are nodes with values 3 and 4. According to the problem requirements, we return the second center node (value 4) and all nodes following it: [4,5,6].
head = [1,2,3][2,3]The linked list has 3 nodes. The center node is at position 2, containing the value 2. We return this node and all subsequent nodes: [2,3].
Constraints