import java.util.*;
/*
* public class ListNode {
* int val;
* ListNode next = null;
* }
*/
public class Solution {
/**
*
* @param head ListNode类
* @param x int整型
* @return ListNode类
*/
public ListNode partition(ListNode head, int x) {
// write code here
if (head == null) {
return null;
}
if (head.next == null) {
return head;
}
ListNode node = head;
ListNode nodes = new ListNode(-1);
ListNode nodeb = new ListNode(-1);
ListNode firstnode = nodes;
ListNode lastnode = nodeb;
while (node != null) {
if (node.val < x) {
ListNode node1 = node;
nodes.next = node1;
nodes = nodes.next;
} else {
ListNode node2 = node;
nodeb.next = node2;
nodeb = nodeb.next;
}
node = node.next;
}
nodeb.next = null;
nodes.next = lastnode.next;
head = firstnode.next;
return head;
}
}