@@ -0,0 +1,2736 @@
+//  Copyright 2016 The Sawdust Open Source Project%0A//%0A// Licensed under the Apache License, Version 2.0 (the %22License%22);%0A// you may not use this file except in compliance with the License.%0A// You may obtain a copy of the License at%0A//%0A//     http://www.apache.org/licenses/LICENSE-2.0%0A//%0A// Unless required by applicable law or agreed to in writing, software%0A// distributed under the License is distributed on an %22AS IS%22 BASIS,%0A// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A// See the License for the specific language governing permissions and%0A// limitations under the License.%0A//%0A/*%0AGiven a linked list and a value x, partition it such that all nodes less than x%0Acome before nodes greater than or equal to x.%0AYou should preserve the original relative order of the nodes in each of the two partitions.%0AFor example,%0AGiven 1-%3E4-%3E3-%3E2-%3E5-%3E2 and x = 3,%0Areturn 1-%3E2-%3E2-%3E4-%3E3-%3E5.%0A */%0A%0Apublic class Leetcode86PartitionList %7B%0A    public class Solution %7B%0A        private ListNode%5B%5D process(ListNode node, int x, ListNode%5B%5D ts) %7B%0A            if (node != null) %7B%0A                if (node.val %3C x) %7B%0A                    ts%5B0%5D.next = node;%0A                    ts%5B0%5D =ts%5B0%5D.next;%0A                %7D else %7B%0A                    ts%5B1%5D.next = node;%0A                    ts%5B1%5D = ts%5B1%5D.next;%0A                %7D%0A               return process(node.next, x, ts);%0A            %7D%0A            return ts;%0A        %7D%0A%0A        public ListNode partition(ListNode head, int x) %7B%0A            ListNode smalsDumyHead = new ListNode(0);%0A            ListNode smalsTail = smalsDumyHead;%0A            ListNode bigsDumyHead = new ListNode(0);%0A            ListNode bigsTail = bigsDumyHead;%0A%0A            ListNode %5B%5D ts = new ListNode %5B%5D%7BsmalsTail,bigsTail%7D;%0A            ts= process( head, x, ts);%0A%0A            ts%5B0%5D.next = bigsDumyHead.next;%0A            ts%5B1%5D.next = null; // note%0A            return smalsDumyHead.next;%0A        %7D%0A%0A        // beats 5.06%25 of java submissions.%0A        public ListNode partition2(ListNode head, int x) %7B%0A            ListNode smalsDumyHead = new ListNode(0);%0A            ListNode smalsTail = smalsDumyHead;%0A            ListNode bigsDumyHead = new ListNode(0);%0A            ListNode bigsTail = bigsDumyHead;%0A%0A            ListNode cur = head;%0A            while (cur != null) %7B%0A                if (cur.val %3C x) %7B%0A                    smalsTail.next = cur;%0A                    smalsTail = smalsTail.next;%0A                %7D else %7B%0A                    bigsTail.next = cur;%0A                    bigsTail = bigsTail.next;%0A                %7D%0A                cur = cur.next;%0A            %7D%0A%0A            smalsTail.next = bigsDumyHead.next;%0A            bigsTail.next = null; // note%0A            return smalsDumyHead.next;%0A        %7D%0A    %7D%0A%7D%0A

Add Leetcode86PartitionList