当前位置:网站首页>LeetCode 21. 合并两个有序链表
LeetCode 21. 合并两个有序链表
2022-08-10 11:09:00 【水菜笔】
原题网址:https://leetcode.cn/problems/merge-two-sorted-lists/submissions/
合并两个排好序的链表;遍历节点;小的当新节点的值;之后后移;在比较;
public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
ListNode l1 = list1;
ListNode l2 = list2;
ListNode dummyHead = new ListNode(-1);
ListNode node = dummyHead;
while( l1 != null && l2 != null) {
ListNode newNode = null;
if(l1.val <l2.val) {
newNode = new ListNode(l1.val);
l1 = l1.next;
} else {
newNode = new ListNode(l2.val);
l2 = l2.next;
}
node.next = newNode;
node = newNode;
}
if(l1 != null) {
node.next = l1;
}
if(l2 != null) {
node.next= l2;
}
return dummyHead.next;
}
边栏推荐
- POJ 2891 Strange Way to Express Integers (Extended Euclidean)
- rider内Mono脚本找不到引用资源
- 使用JMeter进行MySQL的压力测试
- L2 applications from a product perspective: why is it a playground?
- 4 of huawei offer levels, incredibly side is easing the bit in the interview ali?
- 为什么Redis很快
- 第2章-矩阵及其运算-矩阵创建(1)
- Centos7 environment uses Mysql offline installation package to install Mysql5.7
- 老板加薪!看我做的WPF Loading!!!
- Memory problems difficult to locate, it is because you do not use ASAN
猜你喜欢

AUTOCAD——减少样条曲线控制点数、CAD进阶练习(三)

3款不同类型的自媒体免费工具,有效提高创作、运营效率
![[Brave food, not afraid to write the linked list] The problem of the penultimate node of the linked list](/img/87/7ac0307de54f2defe8f72c554745cd.png)
[Brave food, not afraid to write the linked list] The problem of the penultimate node of the linked list

Memory problems difficult to locate, it is because you do not use ASAN

Short video software development - how to break the platform homogenization

mysql appears: ERROR 1524 (HY000): Plugin '123' is not loaded

第3章-线性方程组(3)

How to join We Media, learn about these 5 monetization modes, and make your account quickly monetize

Do self-media monthly income tens of thousands?Several self-media tools that bloggers are using

L2 applications from a product perspective: why is it a playground?
随机推荐
Spss-多元回归案例实操
OSSCore 开源解决方案介绍
ENVI 5.3软件安装包和安装教程
力扣练习——61 根据字符出现频率排序
快手“弃”有赞与微盟“结亲”,电商SaaS行业竞争格局将变?
【勇敢饭饭,不怕刷题之链表】链表反转的几种情况
常量及数据类型你还记得多少?
HDU 6040 Hints of sd0061 (技巧)
学长告诉我,大厂MySQL都是通过SSH连接的
Codeforces 862 C. Mahmoud and Ehab and the xor (技巧)
机器学习之暴力调参案例
不止跑路,拯救误操作rm -rf /*的小伙儿
力扣练习——59 从二叉搜索树到更大和树
自媒体爆款标题怎么写?手把手教你写热门标题
三个绘图工具类详解Paint(画笔)Canvas(画布)Path(路径)
leetcode 823. Binary Trees With Factors(因子二叉树)
LeetCode_152_乘积最大子数组
mysql appears: ERROR 1524 (HY000): Plugin '123' is not loaded
Weilai-software development engineer side record
flask-restplus接口地址404问题