- /*
- 解题思路:
- 通过快慢指针找到中间节点,快指针每次走两步,慢指针每次走一步,当快指针走到结尾的时候,慢指针正好走到中间位置
- */
- typedef struct ListNode Node;
- struct ListNode* middleNode(struct ListNode* head){
- Node* slow = head;
- Node* fast = head;
-
- while(fast!=NULL && fast->next != NULL)
- {
- slow = slow->next;
- fast = fast->next->next;
- }
-
- return slow;
- }