当前位置:网站首页>合并两个有序列表
合并两个有序列表
2022-08-09 12:01:00 【爱敲代码的Harrison】
题目
力扣链接:合并两个有序链表
代码
package com.harrison.class06;
/** * @author Harrison * @create 2022-06-19-17:09 * @motto 众里寻他千百度,蓦然回首,那人却在灯火阑珊处。 */
public class Code09_MergeTwoSortedLists {
public class ListNode {
int val;
ListNode next;
ListNode() {
}
ListNode(int val) {
this.val = val;
}
ListNode(int val, ListNode next) {
this.val = val;
this.next = next;
}
}
public ListNode mergeTwoLists(ListNode head1, ListNode head2) {
if(head1==null || head2==null){
return head1==null?head2:head1;
}
ListNode head=head1.val<=head2.val?head1:head2;
ListNode cur1=head.next;
ListNode cur2=head==head1?head2:head1;
ListNode pre=head;
while(cur1!=null && cur2!=null){
if(cur1.val<=cur2.val){
pre.next=cur1;
cur1=cur1.next;
}else{
pre.next=cur2;
cur2=cur2.next;
}
pre=pre.next;
}
pre.next=cur1!=null?cur1:cur2;
return head;
}
}
边栏推荐
- 非科班AI小哥火了:他没有ML学位,却拿到DeepMind的offer
- AI篮球裁判火了,走步算得特别准,就问哈登慌不慌
- ACM01 Backpack problem
- ARP协议原理
- 数字化转型之支撑保障单元
- HAproxy: load balancing
- The batch size does not have to be a power of 2!The latest conclusions of senior ML scholars
- Information system project managers must memorize the core test sites (63) The main process of project portfolio management & DIPP analysis
- electron 应用开发优秀实践
- 听声辨物,这是AI视觉该干的???|ECCV 2022
猜你喜欢
金融业“限薪令”出台/ 软银出售过半阿里持仓/ DeepMind新实验室成立... 今日更多新鲜事在此...
《数字经济全景白皮书》银行业智能营销应用专题分析 发布
ABAP interview questions: how to use the System CALL interface of the ABAP programming language, direct execution ABAP server operating System's shell command?
Blocking, non-blocking, multiplexing, synchronous, asynchronous, BIO, NIO, AIO all in one pot
shell脚本------函数的格式,传参,变量,递归,数组
基于STM32+铂电阻设计的测温仪
索引index
Reading and writing after separation, performance were up 100%
读写分离后,性能居然提升100%了呀
箭头函数和普通函数的常见区别
随机推荐
数字化转型之支撑保障单元
Web console control edit box
[Microservice ~ Remote Call] Integrate RestTemplate, WebClient, Feign
The redis library cannot be imported
一甲子,正青春,CCF创建六十周年庆典在苏州举行
Apexsqlrecover无法连接数据库
00后写个暑假作业,被监控成这笔样
Experiment record: the process of building a network
你没见过的《老友记》镜头,AI给补出来了|ECCV 2022
ARP协议原理
AQS Synchronization Component - FutureTask Analysis and Use Cases
修改VOT2018.json文件,去掉图片路径中的color
Too much volume... Tencent was asked on the side that the memory was full, what would happen?
WeChat side: what is consistent hashing, usage scenarios, and what problems does it solve?
程序员的专属浪漫——用3D Engine 5分钟实现烟花绽放效果
Adalvo acquires its first branded product, Onsolis
WPF implements a MessageBox message prompt box with a mask
《数字经济全景白皮书》银行业智能营销应用专题分析 发布
ABP 6.0.0-rc.1的新特性
PM2之配置文件