Middle of the Linked List LeetCode solution in C++
1/**2* Definition for singly-linked list.3* struct ListNode {4* int val;5* ListNode *next;6* ListNode() : val(0), next(nullptr) {}7* ListNode(int x) : val(x), next(nullptr) {}8* ListNode(int x, ListNode *next) : val(x), next(next) {}9* };10*/11class Solution {12public:13ListNode *middleNode(ListNode *head) {14ListNode *slow = head;15ListNode *fast = head;16while (fast != NULL && fast->next != NULL) {17slow = slow->next;18fast = fast->next->next;19}20return slow;21}22};