当前位置:网站首页>21. Merge Two Sorted Lists
21. Merge Two Sorted Lists
2022-07-25 09:26:00 【scwMason】
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.
Example:
Input: 1->2->4, 1->3->4 Output: 1->1->2->3->4->4
就是合并两个链表,让他们从小到大排列
时间空间上比较优秀的做法是:
def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode:
if l1 and l2:
if l1.val>l2.val:
l1,l2=l2,l1
l1.next=self.mergeTwoLists(l1.next,l2)
return l1 or l2保持l1是连接最小结点的一个链表,通过不断交换l1和l2来实现。
边栏推荐
- CCF 201503-3 Festival
- Probability theory and mathematical statistics 3 discrete random variables and probability distributions (Part 2)
- CCF 201509-2 date calculation
- SQL 题目整理
- Configuring ROS development environment with vscode: Causes and solutions to the problem of ineffective code modification
- 【建议收藏】靠着这些学习方法,我入职了世界五百强——互联网时代的“奇技淫巧”
- Advanced introduction to digital IC Design SOC
- Redux使用和剖析
- CCF 201509-3 template generation system
- CCF 201503-4 network delay
猜你喜欢

CCF 201503-4 network delay

小程序企业发放红包功能

nodejs链接mysql报错:ER_NOT_SUPPORTED_AUTH_MODEError: ER_NOT_SUPPORTED_AUTH_MODE

【建议收藏】靠着这些学习方法,我入职了世界五百强——互联网时代的“奇技淫巧”

概率机器人学习笔记第二章

JS uses requestanimationframe to detect the FPS frame rate of the current animation in real time

小程序调起微信支付
![严重 [main] org.apache.catalina.util.LifecycleBase.handleSubClassException 初始化组件](/img/39/6f6760e80acec0b02028ea2ed1a5b1.png)
严重 [main] org.apache.catalina.util.LifecycleBase.handleSubClassException 初始化组件

Redis使用场景

车辆属性最近一次入库时间初始化生成sql脚本文件
随机推荐
Detailed explanation of JDBC operation database
四舍五入取近似值
JSP详解
几个常用的网络诊断命令
[nearly 10000 words dry goods] don't let your resume don't match your talent -- teach you to make the most suitable resume by hand
Configuring ROS development environment with vscode: Causes and solutions to the problem of ineffective code modification
记录一些JS工具函数
mysql历史数据补充新数据
数据库MySQL详解
小程序调起微信支付
dp-851
Ubuntu20.04系统下安装MySQL数据库5.7.29版本
Excel导入导出源码分析
Vant problem record
ThreadLocal&Fork/Join
安装 oh my zsh
Introduction to armv8 architecture
DHCP的配置(以华为eNSP为例)
LOAM 融合 IMU 细节之 TransformToEnd 函数
Common methods of JS digital thousand bit segmentation