Tempus Labs processes ordered records represented as singly linked lists. Given the head of a singly linked list, return the value stored in its midpoint node.
Use the second middle node when the list has an even number of nodes. For example, the midpoint of 1 -> 2 -> 3 -> 4 is 3.
Implement midpoint(head), where head is either None or a ListNode with:
val, an integer valuenext, a reference to the next ListNode or NoneReturn the integer value of the midpoint node. The input list is non-empty. Do not modify the list, and do not convert it into another data structure.
def midpoint(head):