# 分隔链表

<p>给你一个链表的头节点 <code>head</code> 和一个特定值<em> </em><code>x</code> ，请你对链表进行分隔，使得所有 <strong>小于</strong> <code>x</code> 的节点都出现在 <strong>大于或等于</strong> <code>x</code> 的节点之前。</p><p>你应当 <strong>保留</strong> 两个分区中每个节点的初始相对位置。</p><p> </p><p><strong>示例 1：</strong></p><img alt="" src="https://img-service.csdnimg.cn/img_convert/54f1177fe2cc4fddce6e1a5553659bee.jpeg" style="width: 662px; height: 222px;" /><pre><strong>输入：</strong>head = [1,4,3,2,5,2], x = 3<strong><br />输出</strong>：[1,2,2,4,3,5]</pre><p><strong>示例 2：</strong></p><pre><strong>输入：</strong>head = [2,1], x = 2<strong><br />输出</strong>：[1,2]</pre><p> </p><p><strong>提示：</strong></p><ul>	<li>链表中节点的数目在范围 <code>[0, 200]</code> 内</li>	<li><code>-100 <= Node.val <= 100</code></li>	<li><code>-200 <= x <= 200</code></li></ul>

## template

```java
public class ListNode {
	int val;
	ListNode next;
	ListNode(int x) {
		val = x;
	}
}
class Solution {
	public ListNode partition(ListNode head, int x) {
		ListNode dummyHead1 = new ListNode(0);
		ListNode dummyHead2 = new ListNode(0);
		ListNode node1 = dummyHead1;
		ListNode node2 = dummyHead2;
		while (head != null) {
			if (head.val < x) {
				node1.next = head;
				head = head.next;
				node1 = node1.next;
				node1.next = null;
			} else {
				node2.next = head;
				head = head.next;
				node2 = node2.next;
				node2.next = null;
			}
		}
		node1.next = dummyHead2.next;
		return dummyHead1.next;
	}
}
```

## 答案

```java

```

## 选项

### A

```java

```

### B

```java

```

### C

```java

```