题目链接https://leetcode-cn.com/problems/middle-of-the-linked-list/
解决方法:采用快慢指针实现
struct ListNode* middleNode(struct ListNode* head){
//采用快慢指针来实现
struct ListNode* slow = head;
struct ListNode* fast = head;
//即使链表一开始只有一个节点,由于此时fast-next = NULL,故不会进入循环,而直接返回第一个节点
while(fast && (fast->next)){
slow = slow->next;
fast = fast->next->next;
}
return slow;
}