Given a non-empty, singly linked list with head node
head
, write a program to return a
middle node of linked list.
If there are even nodes, then there would be two middle nodes, we need to print second middle element.
Example 1
Input: 11->2->13->44->5
Output: 13
Explanation: The middle element of the linked list is 13.
Example 2
Input: 10->2->34->24->15->60
Output: 24
Explanation: As there are even number of nodes, return 24 as it is the second node among two middle elements.