leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

2095.cpp (482B)


0 class Solution { 1 ListNode *pre_mid(ListNode *head) { 2 ListNode *slow = head, *fast = head->next; 3 while (fast && fast->next && fast->next->next) { 4 slow = slow->next; 5 fast = fast->next->next; 6 } 7 return slow; 8 } 9 10 public: 11 ListNode *deleteMiddle(ListNode *head) { 12 if (!head || !head->next) return nullptr; 13 ListNode *pre = pre_mid(head); 14 pre->next = pre->next->next; 15 return head; 16 } 17 };