leetcode算法每天一题 021:合并两个有序链表

从零构建个人知识库:Obsidian与Git实践打造可生长的第二大脑 在信息爆炸的时代,如何有效管理个人知识资产,构建一个可检索、可关联、可生长的个人知识库,成为提升学习效率和创造力的关键。其核心原理在于通过系统化的信息架构与工作流设计,将碎片化信息转化为结构化的知识网络。从技术价值看,这不仅是笔记方法的升级,更是个人知识管理(PKM)和思维模式的革新,能有效对抗信息过载与知识孤岛。实践中,以Obsidian为代表的本地Markdown笔记软件,结合双向链接和关系图谱功能,为知识网络的构建提供了强大支撑;而引入Git进行版本控制,则确保了知识资产的历史可追溯性与安全备份。这种 阅读详情

题目描述

在这里插入图片描述

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* mergeTwoLists(ListNode* list1, ListNode* list2) {
        if(list1 == NULL){return list2;}
        if(list2 == NULL){return list1;}
        ListNode* point =nullptr;
        if( list1->val > list2->val){
               point = list2;
               list2 = list2->next;
           }else{
               point = list1;
               list1 = list1->next;
           }
        ListNode* Head =point;//保存返回值

        while(list1 && list2){
           if( list1->val > list2->val){
               point->next = list2;
               list2 = list2->next;
               point = point->next;
           }else{
               point->next = list1;
               list1 = list1->next;
               point = point->next;
           }
        }
        if(list1!= nullptr){point->next = list1;}
        if(list2!= nullptr){point->next = list2;}

        return Head;
        



    }
};
国产AI芯片实战:用寒武纪MLU370低成本部署DeepSeek-R1,实测推理效果与成本分析 本文详细介绍了寒武纪MLU370芯片在部署DeepSeek-R1大模型时的实战效果与成本优势。通过实测数据对比,MLU370在推理速度、能效比和本地化服务方面表现突出,尤其适合智能客服、内容生成等场景,可显著降低硬件投入和运维成本。 阅读详情

相关推荐

CAN总线错误帧全解析:从数据包到硬件层的故障树分析

本文深入解析CAN总线错误帧的故障树分析方法,从数据包到硬件层全面剖析错误机制。通过物理层信号测试、数据链路层错误解码和应用层协议排查,提供系统化的诊断框架。结合CANoe配置和示波器波形分析,帮助工程师快速定位总线故障,提升系统可靠性。

weixin_26742753的博客 505

力扣(LeetCode)21. 合并两个有序链表(C++)

【墨染】迭代/递归

墨染 898

在Ubuntu上通过Wine完美运行企业微信的详细指南

本文提供了在Ubuntu系统上通过Wine兼容层安装和运行企业微信的详细教程。针对官方未提供Linux版本的痛点,指南推荐使用Ubuntu Kylin团队优化打包的Wine环境,通过简单的命令行步骤即可完成部署,并涵盖启动、中文输入法配置、文件管理等常见问题的解决方案,帮助用户实现高效、稳定的办公沟通。

weixin_29306317的博客 240

C++ : 力扣_Top(1-21)

C++ : 力扣_Top(1-21) 目录: 1、两数之和(简单) 2、两数相加(中等) 3、无重复字符的最长子串(中等) 4、寻找两个有序数组的中位数(困难) 5、最长回文子串(中等) 7、整数反转(简单) 8、字符串转换整数 (atoi)(中等) 10、正则表达式匹配(困难) 11、盛最多水的容器(中等) 13、罗马数字转整数(简单) 14、最长公共前缀(简单) 15、三数之和(中等) 17、...

麻城明歌的博客 819

GNSS数据处理新手避坑:手把手教你用GAMP_GOOD下载IGS/MGEX数据(附.cfg文件详解)

本文详细介绍了如何使用GAMP_GOOD进行GNSS数据处理,从基础配置到高级参数调优,帮助新手避开常见错误。内容包括软件安装、配置文件详解、数据源选择、测站文件配置以及性能优化技巧,特别适合GNSS数据处理初学者快速上手。

weixin_30338481的博客 393

使用Python下载ECMWF的ERA-5数据

一、注册账号 [官网]https://www.ecmwf.int/ 二、登录后获取下载key https://cds.climate.copernicus.eu/api-how-to 如图右侧红色框中的内容复制保存为TXT文件,并重命名为“.cdsapirc”,注意前面有点,保存在 C:\Users\username\.cdsapirc,(WINDOWS系统),username指当前电脑登录账户。 三、安装cdsapi库 以pycharm为例: 在pycharm中依次打开:File>setting

wise_sun的博客 7717

力扣21 合并两个有序链表【C++】

合并两个有序链表 将两个升序链表合并为一个新的 升序 链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。 示例: 输入:1->2->4, 1->3->4 输出:1->1->2->3->4->4 方法一: /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNo.

Estelle 493

当AI写小说——一个被严重低估的工程化战场

摘要 AI小说创作远非简单的prompt生成,而是一项需要系统化工程管理的复杂任务。本文通过真实案例分析,揭示了当前AI写小说存在的五大核心难题:设定一致性难以维持、文风控制缺乏个性、爽感节奏难以把握、长篇记忆能力有限以及平台规则适配困难。研究显示,90%的失败案例源于错误的创作方法,主要表现为对话框式随机生成和模板式同质化创作。要实现高质量的AI小说创作,必须建立包括设定治理、记忆管理、文风校准等在内的全链路工程化体系,而非依赖单一prompt指令。只有采用系统化的人机协同方法,才能突破当前AI创作的质量

sellyogurt的博客 703

LeetCode 23. 合并K个排序链表 c++

分治大法 /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: //合...

See_the_world的博客 337

AI人工智能领域持续学习:提升技术能力的关键

在当今科技飞速发展的时代,AI人工智能已经渗透到我们生活的方方面面。本文章的目的就是帮助大家了解在AI人工智能领域持续学习的重要性,以及如何通过持续学习来提升自己的技术能力。文章会涵盖AI的核心概念、持续学习的原理和方法、实际应用场景等方面,让大家对AI领域的持续学习有一个全面的认识。本文首先会介绍AI人工智能的核心概念,让大家对这个领域有一个初步的了解。然后详细讲解持续学习的原理和方法,通过代码示例展示如何在实际项目中实现持续学习。接着会分析AI持续学习在不同场景的应用,推荐一些学习工具和资源。

AI 原生应用开发的博客 1294

为Ollama本地大模型添加持久化记忆层:openclaw-ollama-memory项目详解

在构建基于大型语言模型(LLM)的对话应用时,上下文管理是核心技术挑战之一。其原理在于模型本身不具备跨会话的持久化记忆能力,每次请求都是独立的。这导致在多轮对话中,模型无法有效利用历史信息,用户体验割裂。从技术价值看,独立的记忆层通过解耦推理与存储,能突破模型固定上下文窗口的限制,实现更智能、连贯的交互。其核心应用场景包括聊天机器人、智能助手及需要长期记忆的复杂代理。本文聚焦的 openclaw-ollama-memory 项目,正是为 Ollama 生态提供的记忆层解决方案,它通过向量检索和智能摘要等机制

weixin_42521558的博客 316

【力扣(LeetCode)】【C/C++】【21.合并两个有序链表】

力扣(LeetCode)

繁华倾夏的博客 259

第3版•系统集成项目管理工程师(中级) │ 告别迷茫!案例分析高分攻略

🥏第3版•系统集成项目管理工程师(中级) │ 告别迷茫!案例分析高分攻略

✨ 欢迎来到【Seal ^_^ 的CSDN博客】!✨ 3883

【力扣】021:合并两个有序链表

题目描述: 将两个有序链表合并为一个新的有序链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。 示例: 输入:1->2->4, 1->3->4 输出:1->1->2->3->4->4 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/merge-two-sorted-lists 算...

Heart_for_Ling的博客 445

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

LeetCode 021:合并两个有序链表

一、写在前面 之前写过的Leetcode笔记:点击查看 今天给大家分享的是LeetCode 021:合并两个有序链表,为面试而生,期待你的加入。 二、今日题目 将两个有序链表合并为一个新的有序链表并返回。 新链表是通过拼接给定的两个链表的所有节点组成的。 示例: 输入:1->2->4, 1->3->4 输出:1->1->2->3->4->4 ...

简说Python的博客 517

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

leetcode 算法题021 (简单007) 合并两个有序链表

leetcode 算法题021 (简单007) 合并两个有序链表 题目介绍 将两个有序链表合并为一个新的有序链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的 示例 输入:1->2->4, 1->3->4 输出:1->1->2->3->4->4 解法一 if(!(l1 && l2)) { return l...

FYuu95100的博客 183

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

Go 算法 leetcode 021 合并两个有序链表

Go 算法 leetcode 021 合并两个有序链表题目链接答案 题目 将两个升序链表合并为一个新的 升序 链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。 链接 leetocde 021 合并两个有序链表 答案 /** * Definition for singly-linked list. * type ListNode struct { * Val int * Next *ListNode * } */ func mergeTwoLists(list1 *Li

kucfire 262

LeetCode Hot 100 - 021 合并两个有序链表

1、由于两个列表有序,所以我们每次插入的值一定比已经存在入的值大。新链表是通过拼接给定的两个链表的所有节点组成的。Hot 100 必刷必会 - 021.合并两个有序链表。2、直接递归遍历两个链表插入数据即可。将两个升序链表合并为一个新的。

SSSHowie的博客 345

021合并两个有序链表 Merge Two Sorted Lists --LeetCode

021 Merge Two Sorted Lists 合并两个有序链表 描述 将两个有序链表合并为一个新的有序链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。 ### 示例: 输入:1->2->4, 1->3->4 输出:1->1->2->3->4->4 思路 从头开始比较已经排序的两个链表,新链表指针每次指向值小的节点,依次比...

NathanniuBee的博客 289

LeetCode 021. 合并两个有序链表 - 双指针与递归详解

题目描述:给定两个升序链表 list1 和 list2,将它们合并为一个新的升序链表并返回。新链表通过拼接原有两个链表的所有节点组成(推荐原地复用节点,不新建节点)。原题链接:https://leetcode.cn/problems/merge-two-sorted-lists/难度等级:Easy相关标签:链表、双指针、递归、模拟。

m0_52114506的博客 910

LeetCode-021合并两个有序链表(Merge Two Sorted Lists)

LeetCode-021 Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. Example Input: 1->2->4, 1->3-&g...

V2beach的博客 244

LeetCode刷题笔记--021. 合并两个有序链表

题目描述: 将两个有序链表合并为一个新的有序链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。 示例: 输入:1-&amp;gt;2-&amp;gt;4, 1-&amp;gt;3-&amp;gt;4 输出:1-&amp;gt;1-&amp;gt;2-&amp;gt;3-&amp;gt;4-&amp;gt;4 分析: 一、维护一个当前节点cur,以及节点l1和l2。若l1和l2非空,如果l1的值小于l2的值,则将l1添加到cur

Liekkas_Javey的博客 440

leetCode-021 - 合并两个有序链表(merge-two-sorted-lists)

021 - 合并两个有序链表(merge-two-sorted-lists) /* * @Author: lvjingshuai * @Date: 2019-07-17 07:29:55 * @Last Modified by: lvjingshuai * @Last Modified time: 2019-08-12 */ 文章结构 1、题目介绍 2、解题 ...

running_shuai的博客 296

LeetCode--021--合并两个有序链表(java)

将两个有序链表合并为一个新的有序链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。 示例: 输入:1->2->4, 1->3->4 输出:1->1->2->3->4->4 哎,这java语法忘完了,也能糊弄通过,老天真要我搞大数据开发吗???????AI我还能刚多久。。。。。。。。。。 1 /** 2 * De...

weixin_33910385的博客 258

021. 合并两个有序链表 | Leetcode题解

点击上方“蓝色字体”,选择“设为星标”每天复习一道面试题,轻松拿大厂Offer~题目描述将两个升序链表合并为一个新的升序链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。 示...

画漫画的程序员∙苏南 255

leetcode[021] -- 合并两个有序链表

一、题目 将两个有序链表合并为一个新的有序链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。 示例: 输入:1->2->4, 1->3->4 输出:1->1->2->3->4->4 二、编码 public ListNode mergeTwoLists(ListNode l1, ListNode l2) { ...

Daria_的博客 182
上一篇: leetcode算法每天一题 020: 有效的括号(c++ stack<> queue<>的简单使用 )
下一篇: leetcode算法每天一题022:括号生成,递归回溯算法(简单剪枝)
FakeOccupational
博客等级 码龄6年 2万+粉丝 1730原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址