Given the head of a singly linked list, return the middle node of the list. If there are two middle nodes (even length), return the second one. Example: Input: head = [1,2,3,4,5] Output: [3] Explanation: 3 is the middle node. Example: Input: head = [1,2,3,4,5,6] Output: [4] Explanation: Two middles (3 and 4), return second one (4). Pattern focus: Fast and Slow Pointers.
head = ListNode
return ListNode
Example 1:
Input:
head = [1,2,3,4,5]
Output:
[3,4,5]
Explanation:
List has 5 nodes; middle is 3 (third node).
Example 2:
Input:
head = [1,2,3,4,5,6]
Output:
[4,5,6]
Explanation:
Even length (6), return 4 (second middle).