偶数为 n/2
奇数为 (n+1)/2
点击查看代码
ListNode* slow = head, *fast = head;
while (fast->next != nullptr && fast->next->next != nullptr) {
slow = slow->next;
fast = fast->next->next;
}
注:需要判断头结点是否为空
标签:head,slow,nullptr,单向,fast,next,链表,中点 From: https://www.cnblogs.com/besnnad/p/17291658.html