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 head; } ListNode left = new ListNode(0); ListNode right = new ListNode(0); ListNode cur = head; ListNode p1 = left; ListNode p2 = right;
while(cur != null){
if(cur.val >= x){
p2.next = cur;
p2 = cur;
} else {
p1.next = cur;
p1 = cur;
}
cur = cur.next;
}
p2.next = null;
p1.next = right.next;
return left.next;
}
}