# 原地址
https://leetcode-cn.com/problems/partition-list/
# 代码提交地址
https://leetcode-cn.com/problems/partition-list/solution/kuai-man-zhi-zhen-by-84858226-o17o/
# 分析
首先,我通过分析发现,只需要把大于X的节点提取出来,最后重新拼接链表就可以。
然后我使用的是快慢两个指针,加一个临时链表实现。
快指针进行移动,如果大于X,就提取出来放入临时链表,同时慢指针跳过当前节点。
如果小于X,则慢指针移动到快指针处。
最后把root链表和临时链表拼接就好了。
# 代码
```java
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public ListNode partition(ListNode head, int x) {
ListNode root =new ListNode(0);
root.next = head;
ListNode temp =new ListNode(0);
ListNode tempHead = temp;
ListNode slow = root; // 原链表修改
ListNode fast = root.next; // 找出大于x的节点
while(fast != null){
ListNode fastNext = fast.next;
if(fast.val < x){
slow = fast;
}else{
temp.next = fast; // 提取大于x的节点
temp = temp.next; // 移动节点
slow.next = fast.next; // 移除大于x的节点
}
fast = fastNext;// fast move
}
temp.next = null;
slow.next = tempHead.next;
return root.next;
}
}
```

86. 分隔链表 (链表)