Even Reverse Time : Space : 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ListNode* reverse(ListNode* A) { ListNode* dummy = new ListNode(-1); ListNode* runner = A; while(runner) { ListNode* nxt = runner->next; runner->next = dummy->next; dummy->next = runner; runner = nxt; } return dummy->next;}ListNode* Solution::solve(ListNode* A) { bool fl = true; ListNode* odd = new ListNode(-1); ListNode* even = new ListNode(-1); ListNode* otail = odd, *etail = even; ListNode* runner = A; while(runner) { if(fl) { otail->next = runner; otail = otail->next; } else { etail->next = runner; etail = etail->next; } runner = runner->next; otail->next = etail->next = NULL; fl = !fl; } ListNode* rev = reverse(even->next); ListNode* res = new ListNode(-1); runner = res; odd = odd->next; fl = true; while(odd or rev) { if(fl) { runner->next = odd; odd = odd->next; } else { runner->next = rev; rev = rev->next; } runner = runner->next; fl = !fl; } return res->next;}