[leetcode]partition-list 分隔链表

. - 力扣(LeetCode)

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;
    }
};

上一篇:在 C# .NET 中,首选静态 HashData 方法而不是 ComputeHash


下一篇:探索一个精美的商品橱窗布局:HTML与CSS的魔法