当前位置:网站首页>剑指 Offer 25. 合并两个排序的链表
剑指 Offer 25. 合并两个排序的链表
2022-07-02 14:21:00 【anieoo】
solution:
归并的思想
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) {
ListNode *dummy = new ListNode(-1);
ListNode *cur = dummy;
while(l1 != NULL && l2 != NULL) {
if(l1->val <= l2->val) {
cur->next = new ListNode(l1->val);
cur = cur->next;
l1 = l1->next;
} else {
cur->next = new ListNode(l2->val);
cur = cur->next;
l2 = l2->next;
}
}
if(l1 != NULL) cur->next = l1;
if(l2 != NULL) cur->next = l2;
return dummy->next;
}
};边栏推荐
- C语言自定义函数的方法
- 易语言abcd排序
- Global and Chinese markets for airport baggage claim conveyors 2022-2028: technology, participants, trends, market size and share Research Report
- The macrogenome microbiome knowledge you want is all here (2022.7)
- 【Leetcode】14. 最長公共前綴
- What is generics- Introduction to generics
- GeoServer:发布PostGIS数据源
- Easy language ABCD sort
- Classic quotations
- The impact of telecommuting on all aspects of our experience | community essay solicitation
猜你喜欢

超卓航科上市:募资9亿市值超60亿 成襄阳首家科创板企业

OpenHarmony如何启动远程设备的FA
![john爆破出現Using default input encoding: UTF-8 Loaded 1 password hash (bcrypt [Blowfish 32/64 X3])](/img/4c/ddf7f8085257d0eb8766dbec251345.png)
john爆破出現Using default input encoding: UTF-8 Loaded 1 password hash (bcrypt [Blowfish 32/64 X3])

易语言abcd排序

Penetration tool - intranet permission maintenance -cobalt strike

TCP congestion control details | 2 background

LeetCode 2. 两数相加

A week of short video platform 30W exposure, small magic push helps physical businesses turn losses into profits

Xiaopeng P7 had an accident on rainy days, and the airbag did not pop up. Official response: the impact strength did not meet the ejection requirements

大厂面试总结大全
随机推荐
你想要的宏基因组-微生物组知识全在这(2022.7)
MOSFET器件手册关键参数解读
小鹏P7雨天出事故安全气囊没有弹出 官方回应:撞击力度未达到弹出要求
国内比较好的OJ平台[通俗易懂]
PWM controlled steering gear
LeetCode 4. Find the median (hard) of two positive arrays
绿竹生物冲刺港股:年期内亏损超5亿 泰格医药与北京亦庄是股东
R and rstudio download and installation tutorial (super detailed)
Global and Chinese market of discharge machines 2022-2028: Research Report on technology, participants, trends, market size and share
Xiaopeng P7 had an accident on rainy days, and the airbag did not pop up. Official response: the impact strength did not meet the ejection requirements
大厂面试总结大全
电脑自带软件使图片底色变为透明(抠图白底)
What is generics- Introduction to generics
PWM breathing lamp
深度学习图像数据自动标注[通俗易懂]
2、 Expansion of mock platform
关于举办科技期刊青年编辑沙龙——新时代青年编辑应具备的能力及提升策略的通知...
二、mock平台的扩展
宝宝巴士创业板IPO被终止:曾拟募资18亿 唐光宇控制47%股权
Learning Weekly - total issue 60 - 25th week of 2022