/**

  • 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) { if(head==NULL) return; vector<ListNode *> tmp; ListNode *node=head; while(node!=NULL){ tmp.push_back(node); node=(*node).next; } node=head; for(auto i=tmp.end()-1;true;--i){ if((*i)==(*node).next || (*i)==(node)){ (**i).next=NULL; break; } (**i).next=(*node).next; (*node).next=*i; node=(**i).next; } } };