public class Solution {
public void reorderList(ListNode head) {
if (head == null) {
return;
}
List<ListNode> array = new ArrayList<>();
ListNode node = head;
while (node != null) {
array.add(node);
node = node.next;
}
int left = 0;
int right = array.size() - 1;
while (left < right) {
array.get(left).next = array.get(right);
left++;
if(left == right){
break;
}
array.get(right).next = array.get(left);
right--;
}
array.get(left).next = null;
}
}