@@ -0,0 +1,1345 @@
+package leetcode.reorder_list;%0A%0Aimport java.util.ArrayList;%0A%0Aimport common.ListNode;%0A%0Apublic class Solution %7B%0A%09public void reorderList(ListNode head) %7B%0A%09%09if(head == null %7C%7C head.next == null) return;%0A%09%09ListNode cur = head;%0A%09%09ListNode tail = null;%0A%09%09int cnt = 0;%0A%09%09while(cur != null)%7B%0A%09%09%09cnt++;%0A%09%09%09cur = cur.next;%0A%09%09%7D%0A%09%09cnt = (cnt + 1) / 2;%0A%09%09%0A%09%09cur = head;%0A%09%09while(cnt %3E 1)%7B%0A%09%09%09cur = cur.next;%0A%09%09%09cnt--;%0A%09%09%7D%0A%09%09%0A%09%09ListNode prev = cur;%0A%09%09ListNode nxt = prev.next;%0A%09%09prev.next = null;%0A%09%09prev = null;%0A%09%09while(nxt != null)%7B%0A%09%09%09ListNode tmp = nxt.next;%0A%09%09%09nxt.next = prev;%0A%09%09%09prev = nxt;%0A%09%09%09nxt = tmp;%0A%09%09%7D%0A%09%09tail = prev;%0A%09%09ListNode back = tail, forward = head;%0A%09%09while(back != null && forward != null)%7B%0A%09%09%09ListNode ff = forward.next;%0A%09%09%09ListNode bb = back.next;%0A%09%09%09forward.next = back;%0A%09%09%09back.next = ff;%0A%09%09%09back = bb;%0A%09%09%09forward = ff;%0A%09%09%7D%0A%09%7D%0A%09%0A%09public static void dumpList(ListNode head)%7B%0A%09%09ListNode cur = head;%0A%09%09while(cur != null)%7B%0A%09%09%09System.err.print(%22%22 + cur.val + %22, %22);%0A%09%09%09cur = cur.next;%0A%09%09%7D%0A%09%09System.err.println(%22%22);%0A%09%7D%0A%09%0A%09public static void main(String%5B%5D args)%7B%0A%09%09final int N = 9;%0A%09%09ArrayList%3CListNode%3E nodeAry = new ArrayList%3CListNode%3E();%0A%09%09for(int i = 0; i %3C N; i++)%7B%0A%09%09%09nodeAry.add(new ListNode(i));%0A%09%09%09if(i %3E 0) nodeAry.get(i - 1).next = nodeAry.get(i);%0A%09%09%7D%0A%09%09new Solution().reorderList(nodeAry.get(0));%0A%09%09dumpList(nodeAry.get(0));%0A%09%7D%0A%7D%0A

Add java solution for 143. Reorder List