find middle of a linked list

ListNode* findMiddle(ListNode* root) {
    ListNode* slow = root;
    ListNode* fast = root;

    while (fast && fast->next) {
        slow = slow->next;
        fast = fast->next->next;
    }
    
    return slow; // This is the middle node
}