leetcode链接 876. 链表的中间结点
给你单链表的头结点 head ,请你找出并返回链表的中间结点。
如果有两个中间结点,则返回第二个中间结点。
struct ListNode {
int val;
struct ListNode* next;
};
typedef struct ListNode ListNode;
ListNode* MiddleNode(ListNode* head) {
ListNode* slow = head,
* quick = head;
while (quick && quick->next) {
slow = slow->next;
quick = quick->next->next;
}
return slow;
}