0876.cpp (330B)
1 class Solution { 2 public: 3 ListNode *middleNode(ListNode *head) { 4 ListNode *fast, *slow; 5 fast = slow = head; 6 while (fast->next && fast->next->next) { 7 fast = fast->next->next; 8 slow = slow->next; 9 } 10 if (fast->next) slow = slow->next; 11 12 return slow; 13 } 14 };