struct ListNode
{
    int val;
    ListNode *next;
    ListNode() : val(0), next(nullptr) {}
    ListNode(int x) : val(x), next(nullptr) {}
    ListNode(int x, ListNode *next) : val(x), next(next) {}
};

//利用数组可以索引来做
class Solution
{
public:
    void reorderList(ListNode *head)
    {
        if (head == nullptr || head->next == nullptr || head->next->next == nullptr)
            return;
        ListNode *cur = head;
        vector<ListNode *> vec;
        while (cur)
        {
            // vec.push_back(cur);
            vec.emplace_back(cur);
            cur = cur->next;
        }
        int i = 0, j = vec.size() - 1;
        while (i < j)
        {
            if (i == j)
                break;
            vec[i]->next = vec[j];
            vec[j]->next = vec[i + 1];
            i++;
            j--;
        }
        vec[i]->next = nullptr;
    }
};
