当前位置:网站首页>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
- 从源码角度分析UUID的实现原理
- 实现内网穿透的最佳解决方案(无实名认证,完全免费)
- 力扣练习——62 有效的数独
- LeetCode 24. 两两交换链表中的节点
- 面试官:你们是如何保证接口的幂等性?
- Pulling drills - 56 Finding the right interval
- How to join We Media, learn about these 5 monetization modes, and make your account quickly monetize
- 基于UiAutomator2+PageObject模式开展APP自动化测试实战
- 老板加薪!看我做的WPF Loading!!!
猜你喜欢

个推数据资产管理经验 | 教你打造数据质量心电图,智能检测数据“心跳”异常

微信小程序,全局变量一个地方改变了其他地方的状态也跟着改变。

Module 9 - Designing an e-commerce seckill system

OPNsense安装配置Zenarmor

老板加薪!看我做的WPF Loading!!!

gpu-admission 源码分析

Analysis of the implementation principle of UUID from the perspective of source code

Does your child lack self-discipline?Ape Counseling: Pay attention to "blank" in the schedule to give children more control

使用哈工大LTP测试分词并且增加自定义字典

推荐6个自媒体领域,轻松易上手
随机推荐
HDU 4372:Count the Buildings (Stirling数)
使用哈工大LTP测试分词并且增加自定义字典
LeetCode 61. 旋转链表
再有人问你分布式事务,把这篇扔给他
推荐6个自媒体领域,轻松易上手
APP automation testing practice based on UiAutomator2+PageObject mode
可视化服务编排在金融APP中的实践
老板加薪!看我做的WPF Loading!!!
LeetCode50天刷题计划(Day 19—— 在排序数组中查找元素的第一个和最后一个位置(9.10-10.40)
Codeforces 862 C. Mahmoud and Ehab and the xor (技巧)
Nocalhost - 让云原生时代的开发更高效
Analysis of the implementation principle of UUID from the perspective of source code
gpu-admission 源码分析
Does your child lack self-discipline?Ape Counseling: Pay attention to "blank" in the schedule to give children more control
石墨文档打开文档时快速定位到上次写的位置
【mysql】explain介绍[通俗易懂]
LAXCUS分布式操作系统安全管理
LeetCode 369. Plus One Linked List
[E-commerce operation] Do you really understand social media marketing (SMM)?
有哪些好用的性能测试工具推荐?性能测试报告收费标准