难度
<a name="P3fYt"></a>## 题解```java/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */class Solution { public ListNode partition(ListNode head, int x) { ListNode smallHead = new ListNode(0); ListNode largeHead = new ListNode(0); ListNode small = smallHead; ListNode large = largeHead; ListNode cur = head; while(cur != null) { if(cur.val >= x) { large.next = cur; large = large.next; } else { small.next = cur; small = small.next; } cur = cur.next; } small.next = largeHead.next; large.next = null; return smallHead.next; }}