2095. Delete the Middle Node of a Linked List 發表於 2023-02-13 | 分類於 leetcode problemsolution1234567891011121314class Solution {public: ListNode* deleteMiddle(ListNode* head) { if(!head->next) return nullptr; ListNode * pre = head, * slow = head, *fast = head; while(fast && fast->next){ pre = slow; slow = slow->next; fast = fast->next->next; } pre->next = slow->next; return head; }};s analysis time complexity O(n) space complexity O(1)