-
Notifications
You must be signed in to change notification settings - Fork 0
86. Partition List
PuChen0211 edited this page Jul 13, 2016
·
1 revision
ListNode* partition(ListNode* head, int x) {
ListNode left(0);
ListNode right(0);
ListNode *lp = &left;
ListNode *rp = &right;
while (head) {
if(head->val < x){
lp->next = head;
lp = lp->next;
}
else{
rp->next = head;
rp = rp->next;
}
head = head->next;
}
lp->next = right.next;
rp->next = nullptr;
return left.next;
}