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

相关推荐

  1. 【STL】(list)

    2024-07-12 01:30:02       34 阅读
  2. freertos 源码分析list数据结构

    2024-07-12 01:30:02       43 阅读
  3. C++之list

    2024-07-12 01:30:02       42 阅读
  4. list()容器(二)

    2024-07-12 01:30:02       37 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-12 01:30:02       66 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-12 01:30:02       70 阅读
  3. 在Django里面运行非项目文件

    2024-07-12 01:30:02       57 阅读
  4. Python语言-面向对象

    2024-07-12 01:30:02       68 阅读

热门阅读

  1. kotlin flow collect collectLatest 区别

    2024-07-12 01:30:02       23 阅读
  2. 搜维尔科技:触觉反馈数据手套CyberGlove击鼓测试

    2024-07-12 01:30:02       19 阅读
  3. c语言变量修饰词

    2024-07-12 01:30:02       22 阅读
  4. 文心一言使用指南

    2024-07-12 01:30:02       25 阅读
  5. Redis数据同步

    2024-07-12 01:30:02       26 阅读
  6. 11、中台-DDD-几种微服务架构模型对比分析

    2024-07-12 01:30:02       23 阅读