题目
解题思路
总代码
class Solution {
public ListNode partition(ListNode head, int x) {
ListNode prev1=new ListNode();
ListNode cur1=prev1;
ListNode prev2=new ListNode();
ListNode cur2=prev2;
while(head!=null){
if(head.val<x){
cur1.next=head;
cur1=cur1.next;
head=head.next;
}else{
cur2.next=head;
cur2=cur2.next;
head=head.next;
}
}
cur1.next=prev2.next;
cur2.next=null;
return prev1.next;
}
}