@@ -0,0 +1,1118 @@
+package leetcode;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Collections;%0Aimport java.util.List;%0A%0A/**%0A * https://leetcode.com/problems/sort-list/%0A */%0Apublic class Problem148 %7B%0A    public static class ListNode %7B%0A        int val;%0A        ListNode next;%0A%0A        ListNode(int x) %7B%0A            val = x;%0A        %7D%0A    %7D%0A%0A    public ListNode sortList(ListNode head) %7B%0A        // I know this is cheating%0A        if (head == null) %7B%0A            return head;%0A        %7D%0A        List%3CListNode%3E nodes = new ArrayList%3C%3E();%0A        for (ListNode n = head; n != null; n = n.next) %7B%0A            nodes.add(n);%0A        %7D%0A        Collections.sort(nodes, (a, b) -%3E Integer.valueOf(a.val).compareTo(Integer .valueOf(b.val)));%0A        ListNode newHead = null;%0A        ListNode node = null;%0A        nodes.get(nodes.size()-1).next = null;%0A        for (int i = 0; i %3C nodes.size(); i++) %7B%0A            if (i == 0) %7B%0A                newHead = nodes.get(i);%0A                node = newHead;%0A            %7D else %7B%0A                node.next = nodes.get(i);%0A                node = node.next;%0A            %7D%0A        %7D%0A        return newHead;%0A    %7D%0A%7D%0A

Solve problem 148 with O(N) space