当前位置:网站首页>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 macrogenome microbiome knowledge you want is all here (2022.7)
- Does digicert SSL certificate support Chinese domain name application?
- 深度之眼(三)——矩阵的行列式
- Digital IC hand tearing code -- voting device
- TCP congestion control details | 2 background
- Vscode setting delete line shortcut [easy to understand]
- 【云原生】简单谈谈海量数据采集组件Flume的理解
- LeetCode 1. Sum of two numbers
- Understand one article: four types of data index system
- Configure MySQL under Linux to authorize a user to access remotely, which is not restricted by IP
猜你喜欢

A case study of college entrance examination prediction based on multivariate time series

易语言abcd排序

剑指 Offer 22. 链表中倒数第k个节点

MOSFET器件手册关键参数解读

Believe in yourself and finish the JVM interview this time

871. 最低加油次数

Penetration tool - intranet permission maintenance -cobalt strike

移动应用性能工具探索之路

小鹏P7雨天出事故安全气囊没有弹出 官方回应:撞击力度未达到弹出要求

GeoServer:发布PostGIS数据源
随机推荐
john爆破出現Using default input encoding: UTF-8 Loaded 1 password hash (bcrypt [Blowfish 32/64 X3])
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
2322. 从树中删除边的最小分数(异或和&模拟)
[essay solicitation activity] Dear developer, RT thread community calls you to contribute
Yolov5 practice: teach object detection by hand
A case study of college entrance examination prediction based on multivariate time series
PWM breathing lamp
A few lines of code to complete RPC service registration and discovery
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
Role and function of uboot
Weili holdings listed on the Hong Kong Stock Exchange: with a market value of HK $500million, it contributed an IPO to Hubei
【征文活动】亲爱的开发者,RT-Thread社区喊你投稿啦
Fuyuan medicine is listed on the Shanghai Stock Exchange: the market value is 10.5 billion, and Hu Baifan is worth more than 4billion
【Leetcode】13. 罗马数字转整数
电脑自带软件使图片底色变为透明(抠图白底)
John blasting appears using default input encoding: UTF-8 loaded 1 password hash (bcrypt [blowfish 32/64 x3])
ThreadLocal
LeetCode 4. Find the median (hard) of two positive arrays
深度之眼(三)——矩阵的行列式
What is generics- Introduction to generics