当前位置:网站首页>LeetCode 21. Merge two ordered linked lists
LeetCode 21. Merge two ordered linked lists
2022-08-10 11:58:00 【Mizuna pen】
原题网址:https://leetcode.cn/problems/merge-two-sorted-lists/submissions/
合并两个排好序的链表;遍历节点;Small when the value of the new node;move back after;在比较;
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;
}
边栏推荐
- OPNsense安装配置Zenarmor
- 因为找不到lombok而找不到符号log
- 快速上手,征服三种不同分布式架构调用方案
- 石墨文档打开文档时快速定位到上次写的位置
- ssm框架搭建过程[通俗易懂]
- jlink and swd interface definition
- Interviewer: How are Dao, Service, Controller, Util, and Model divided in the project?
- 使用.NET简单实现一个Redis的高性能克隆版(六)
- Apple bucks the trend and expands iPhone 14 series stocking, with a total of 95 million units
- 3款不同类型的自媒体免费工具,有效提高创作、运营效率
猜你喜欢
Go 事,Gopher 要学的数字类型,变量,常量,运算符 ,第2篇
学长告诉我,大厂MySQL都是通过SSH连接的
建校仅11年就入选“双一流” ,这所高校是凭什么做到的?
老板加薪!看我做的WPF Loading!!!
Module 9 - Designing an e-commerce seckill system
微信小程序提交审核历史版本记录从哪里查看
Analysis of the implementation principle of UUID from the perspective of source code
常量及数据类型你还记得多少?
从源码角度分析UUID的实现原理
VSCode remote connection server error: Could not establish connection to "xxxxxx" possible error reasons and solutions
随机推荐
Centos7 environment uses Mysql offline installation package to install Mysql5.7
即时零售业态下如何实现自动做账?
flask-restplus接口地址404问题
网络基础(第一节)
基于UiAutomator2+PageObject模式开展APP自动化测试实战
不止跑路,拯救误操作rm -rf /*的小伙儿
不止跑路,拯救误操作rm -rf /*的小伙儿
力扣练习—— 矩形区域不超过 K 的最大数值和(hard)
AutoCAD Map 3D功能之一暴力处理悬挂点(延伸)
HDU 4372:Count the Buildings (Stirling数)
使用JMeter进行MySQL的压力测试
可视化服务编排在金融APP中的实践
OPNsense安装配置Zenarmor
接口定义与实现
Nocalhost - Making development more efficient in the cloud-native era
Analysis of the name matching process between the LCD driver and the device (Tiny4412)
石墨文档打开文档时快速定位到上次写的位置
mpf6_Time Series Data_quandl_correct kernel PCA_AIC_BIC_trend_log_return_seasonal_decompose_sARIMAx_ADFull
暑期总结4
LeetCode 61. 旋转链表