086. Partition List Posted on 2017-10-12 | In LeetCode Solution 1: accepted 1msKeep a tail pointer when we need the end node. 1234567891011121314151617181920212223public ListNode partition(ListNode head, int x) { ListNode leftHead = new ListNode(0); ListNode left = leftHead; ListNode rightHead = new ListNode(0); ListNode right = rightHead; ListNode next = null; while (head != null) { next = head.next; head.next = null; if (head.val < x) { left.next = head; left = head; } else { right.next = head; right = head; } head = next; } left.next = rightHead.next; // left = leftHead if no elements were sorted to left return leftHead.next;}