public static LinkedListNode partition(LinkedListNode n, int x) {
		LinkedListNode before = null;
		LinkedListNode after = null;

		while (n != null) {
			LinkedListNode node = n.next;
			if (n.val < x) {
				n.next = before;
				before = n;

			} else {
				n.next = after;
				after = n;
			}
			n = node;
		}
		
		if(before == null)
			return after;
		LinkedListNode head = before;
		while(before.next != null) {
			before = before.next;
		}
		before.next = after;
		return head;
	}