/**

  • Definition for singly-linked list.

  • struct ListNode {

  • int val;
    
  • ListNode *next;
    
  • ListNode(int x) : val(x), next(NULL) {}
    
  • }; */ class Solution { public: void reorderList(ListNode *head) { vector res; auto t = head; while(head) { res.push_back(head -> val); head = head -> next; } head = t; vector ans; int i = 0, j = res.size() - 1; for(i = 0, j = res.size() - 1; i < j; i ++ , j -- ) { ans.push_back(res[i]); ans.push_back(res[j]); } if(i == j) { ans.push_back(res[i]); } i = 0;

     while(head)
     {
         head -> val = ans[i ++];
         cout << head -> val;
         head = head -> next;
     }
    

    } };