Middle of the Linked List
Easy
LC #876
fast & slow pointersNot attempted yet
Given the head of a non-empty singly linked list,
return its middle node. If the list has an even number of
nodes, there are two middles: return the second one.
The result is the list starting at that node.
Example 1
Input: head = [1,2,3,4,5]
Output: [3,4,5]
Example 2
Input: head = [1,2,3,4,5,6]
Output: [4,5,6]
Two middles (3 and 4): return 4.
Example 3
Input: head = [9]
Output: [9]
Constraints
- 1 ≤ number of nodes ≤ 10⁵
- 1 ≤ Node.val ≤ 10⁵