ListNode* partition(ListNode* head, int x) {
ListNode res(0), mid(0);
if (!head) return NULL;
ListNode* small=&res;
ListNode* big=∣
while (head) {
if (head->val < x) {
small->next = head;
small = small->next;
}
else {
big->next = head;
big = big->next;
}
head = head->next;
}
big->next = NULL;
small->next = mid.next;
return res.next;
}