当前位置:网站首页>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;
}
};边栏推荐
- 社交元宇宙平台Soul冲刺港股:年营收12.8亿 腾讯是股东
- TCP congestion control details | 2 background
- Does digicert SSL certificate support Chinese domain name application?
- Digital IC hand tearing code -- voting device
- [cloud native] briefly talk about the understanding of flume, a massive data collection component
- Cell: Tsinghua Chenggong group revealed an odor of skin flora. Volatiles promote flavivirus to infect the host and attract mosquitoes
- 移动应用性能工具探索之路
- Green bamboo biological sprint Hong Kong stocks: loss of more than 500million during the year, tiger medicine and Beijing Yizhuang are shareholders
- 畅玩集团冲刺港股:年营收2.89亿 刘辉有53.46%投票权
- 只是巧合?苹果iOS16的神秘技术竟然与中国企业5年前产品一致!
猜你喜欢

Rock PI Development Notes (II): start with rock PI 4B plus (based on Ruixing micro rk3399) board and make system operation

Amazon cloud technology community builder application window opens

Yolov5 practice: teach object detection by hand
![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])

Hard core! One configuration center for 8 classes!
![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])

DGraph: 大规模动态图数据集

酒仙网IPO被终止:曾拟募资10亿 红杉与东方富海是股东

DigiCert SSL证书支持中文域名申请吗?

超卓航科上市:募资9亿市值超60亿 成襄阳首家科创板企业
随机推荐
VMware安装win10镜像
Exploration and practice of integration of streaming and wholesale in jd.com
MOSFET器件手册关键参数解读
john爆破出现Using default input encoding: UTF-8 Loaded 1 password hash (bcrypt [Blowfish 32/64 X3])
国内比较好的OJ平台[通俗易懂]
社交元宇宙平台Soul冲刺港股:年营收12.8亿 腾讯是股东
PhD Debate-11 预告 | 回顾与展望神经网络的后门攻击与防御
AP and F107 data sources and processing
Method of C language self defining function
Error when uploading code to remote warehouse: remote origin already exists
深度之眼(三)——矩阵的行列式
vscode设置删除行快捷键[通俗易懂]
Cell:清华程功组揭示皮肤菌群的一种气味挥发物促进黄病毒感染宿主吸引蚊虫...
JS delete substring in string
Vscode setting delete line shortcut [easy to understand]
LeetCode 5. Longest Palindromic Substring
一文看懂:数据指标体系的4大类型
linux下配置Mysql授权某个用户远程访问,不受ip限制
剑指 Offer 21. 调整数组顺序使奇数位于偶数前面
MySQL port