### 解题思路

新建两个链表头,按照归并排序的思想依次将小于x和大于x的节点插入表头

后连接两个表

### 代码

class Solution {
public:
    ListNode* partition(ListNode* head, int x) {
        ListNode* lt = new ListNode(-1);
        ListNode* rt = new ListNode(-1);
        ListNode* lh = lt;
        ListNode* rh = rt;
        for(auto p = head;p;p=p->next){
            if(p->val < x) lt = lt->next = p;
            else rt = rt->next = p;
        }
        lt->next = rh->next;
        rt->next = nullptr;
        return lh->next;
    }
};