Given the head of a singly linked list, return the middle node of the linked list.

If there are two middle nodes, return the second middle node.

&nbsp;
Example 1:

Input: head = [1,2,3,4,5]
Output: [3,4,5]
Explanation: The middle node of the list is node 3.


Example 2:

Input: head = [1,2,3,4,5,6]
Output: [4,5,6]
Explanation: Since the list has two middle nodes with values 3 and 4, we return the second one.


&nbsp;
Constraints:


	The number of nodes in the list is in the range [1, 100].
	1 &lt;= Node.val &lt;= 100


class Solution:
    def middleNode(self, head: Optional[ListNode]) -> Optional[ListNode]:
        # basically we create two pointers
        # move one pointer extra fast
        # another pointer would be slow
        # when fast reaches end slow would be in mid
        slow = fast = head
        while fast and fast.next:
            slow = slow.next
            fast = fast.next.next
        return slow
class Solution {
    public ListNode middleNode(ListNode head) {
        
        ListNode temp = head;
        int size = 0;
        while(temp!=null){
            size++;
            temp = temp.next;
        }
        int mid = size/2;
        temp = head;
        for(int i=0;i<mid;i++){
            temp = temp.next;
        }
        
        return temp;
        
    }
}
/**
 * Definition for singly-linked list.
 * struct ListNode {
 * int val;
 * ListNode *next;
 * ListNode() : val(0), next(nullptr) {}
 * ListNode(int x) : val(x), next(nullptr) {}
 * ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* middleNode(ListNode* head) {
         ListNode * slow=head;
        ListNode * fast=head;
        while(fast!=NULL && fast->next!=NULL){
            slow=slow->next;
            fast=fast->next->next;
        }
        return slow;
    }
};
var middleNode = function(head) {
    var runner1 = head
    var runner2 = head?.next
    while(runner1 && runner2) {
        runner1 = runner1?.next
        runner2 = (runner2?.next)?.next
    }
    return runner1
};
Middle of the Linked List