June 23, 2022 · 1 min read
https://leetcode.com/problems/middle-of-the-linked-list/
class Solution {
public:
ListNode *middleNode(ListNode *head) {
ListNode *slow = head;
ListNode *fast = head;
while (fast != nullptr && fast->next != nullptr) {
slow = slow->next;
fast = fast->next->next;
}
return slow;
}
};