ListNode* reorderList(ListNode* head){ if (!head) return head; ListNode* h = head; vector<ListNode *> collection; while (h) { collection.push_back(h); h = h->next; } int size = collection.size(); int n = size / 2; for (int i = 0; i < n; i++) { int right = size - 1 - i; collection[i]->next = collection[right]; collection[right]->next = collection[i + 1];
if (i == n - 1 && size % 2 == 0) { collection[right]->next = nullptr; } if (i == n - 1 && size % 2 != 0) { collection[right]->next->next = nullptr; } } return head; }