You are given the head of a singly linked list. Your task is to find and return the middle node of the linked list. If the linked list contains an even number of nodes, return the second middle node.
Example 1
Input: head = [1,2,3,4,5]
Output: 3
Explanation: The linked list contains 5 nodes. The middle node is 3.
Example 2
Input: head = [1,2,3,4,5,6]
Output: 4
Explanation: The linked list contains 6 nodes. There are two middle nodes (3 and 4), so the second middle node, 4, is returned.
Example 3
Input: head = [10]
Output: 10
Explanation: The linked list contains only one node, so it is the middle node.
Sign in to write, run, and submit your solution against the full test suite.