/**
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
class Solution {
public:
/**
*
* @param head ListNode类
* @param x int整型
* @return ListNode类
*/
ListNode* partition(ListNode* head, int x) {
// write code here
ListNode* pre = new ListNode(0);
ListNode* post = new ListNode(0);
ListNode* a = pre;
ListNode* b = post;
ListNode* cur = head;
while(cur != nullptr){
if(cur->val < x){
a->next = cur;
a = cur;
cur = cur->next;
}
else{
b->next = cur;
b = cur;
cur = cur->next;
}
}
a->next = post->next;
b->next = nullptr;
return pre->next;
}
};