当前位置:网站首页>Sword finger offer 25 Merge two sorted linked lists
Sword finger offer 25 Merge two sorted linked lists
2022-07-02 17:12:00 【anieoo】
Original link : The finger of the sword Offer 25. Merge two ordered linked lists
solution:
The idea of merging
/**
* 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;
}
};边栏推荐
- The impact of telecommuting on all aspects of our experience | community essay solicitation
- Executive engine module of high performance data warehouse practice based on Impala
- &lt; IV & gt; H264 decode output YUV file
- 配置基于接口的ARP表项限制和端口安全(限制用户私自接入傻瓜交换机或非法主机接入)
- 剑指 Offer 26. 树的子结构
- go-zero微服务实战系列(八、如何处理每秒上万次的下单请求)
- 七张图,学会做有价值的经营分析
- 超卓航科上市:募资9亿市值超60亿 成襄阳首家科创板企业
- 剑指 Offer 25. 合并两个排序的链表
- LeetCode 5. Longest Palindromic Substring
猜你喜欢

关于举办科技期刊青年编辑沙龙——新时代青年编辑应具备的能力及提升策略的通知...

Yolov5 practice: teach object detection by hand

智能垃圾桶(五)——点亮OLED

剑指 Offer 24. 反转链表
![[error record] error -32000 received from application: there are no running service protocol](/img/6c/66099650de46cac88b805e6cfb90b9.jpg)
[error record] error -32000 received from application: there are no running service protocol

Notice on holding a salon for young editors of scientific and Technological Journals -- the abilities and promotion strategies that young editors should have in the new era

Go zero micro service practical series (VIII. How to handle tens of thousands of order requests per second)

伟立控股港交所上市:市值5亿港元 为湖北贡献一个IPO
![John blasting appears using default input encoding: UTF-8 loaded 1 password hash (bcrypt [blowfish 32/64 x3])](/img/4c/ddf7f8085257d0eb8766dbec251345.png)
John blasting appears using default input encoding: UTF-8 loaded 1 password hash (bcrypt [blowfish 32/64 x3])

TCP congestion control details | 2 background
随机推荐
Serial port controls steering gear rotation
福元医药上交所上市:市值105亿 胡柏藩身价超40亿
OpenPose的使用
Day 18 of leetcode dynamic planning introduction
一年顶十年
John blasting appears using default input encoding: UTF-8 loaded 1 password hash (bcrypt [blowfish 32/64 x3])
&lt;四&gt; H264解码输出yuv文件
2020 "Lenovo Cup" National College programming online Invitational Competition and the third Shanghai University of technology programming competition (a sign in, B sign in, C sign in, D thinking +mst
IP地址转换地址段
Cell:清华程功组揭示皮肤菌群的一种气味挥发物促进黄病毒感染宿主吸引蚊虫...
Understand one article: four types of data index system
Amazon cloud technology community builder application window opens
System Verilog implements priority arbiter
IP address translation address segment
The macrogenome microbiome knowledge you want is all here (2022.7)
Detailed explanation of @accessories annotation of Lombok plug-in
【Leetcode】14. 最長公共前綴
人生的开始
Talk about an experience of job hopping and being rejected
Vscode setting delete line shortcut [easy to understand]