86.Partition List
Posted smallredness
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了86.Partition List相关的知识,希望对你有一定的参考价值。
class Solution {
public:
ListNode *partition(ListNode *head, int x) {
ListNode *dummy = new ListNode(-1);
dummy->next = head;
ListNode *pre = dummy, *cur = head;;
while (pre->next && pre->next->val < x) pre = pre->next;
cur = pre;
while (cur->next) {
if (cur->next->val < x) {
ListNode *tmp = cur->next;
cur->next = tmp->next;
tmp->next = pre->next;
pre->next = tmp;
pre = pre->next;
} else {
cur = cur->next;
}
}
return dummy->next;
}
};
以上是关于86.Partition List的主要内容,如果未能解决你的问题,请参考以下文章