class Solution {
public:
ListNode* partition(ListNode* head, int x) {
ListNode *smlDummy = new ListNode(0), *bigDummy = new ListNode(0);
ListNode *sml = smlDummy, *big = bigDummy;
while (head != nullptr) {
if (head->val < x) {
sml->next = head;
sml = sml->next;
} else {
big->next = head;
big = big->next;
}
head = head->next;
}
sml->next = bigDummy->next;
big->next = nullptr;
return smlDummy->next;
}
};
本站资源均来自互联网,仅供研究学习,禁止违法使用和商用,产生法律纠纷本站概不负责!如果侵犯了您的权益请与我们联系!
转载请注明出处: 免费源码网-免费的源码资源网站 » [leetcode]partition-list 分隔链表
发表评论 取消回复