当前位置:网站首页>12--合并两个有序链表
12--合并两个有序链表
2022-06-24 06:56:00 【JH_Cao】
合并两个有序链表
- 思路很简单,对链表写起来不熟悉
- 递归思路

class xiapi_12 {
func mergeTwoLists(_ list1: ListNode12?, _ list2: ListNode12?) -> ListNode12? {
if list2 == nil {
return list1
}
if list1 == nil {
return list2
}
if list1?.val ?? 0 < list2?.val ?? 0 {
list1?.next = mergeTwoLists(list1?.next, list2)
return list1
} else {
list2?.next = mergeTwoLists(list2?.next, list1)
return list2
}
}
}
public class ListNode12 {
public var val: Int
public var next: ListNode12?
public init() {
self.val = 0; self.next = nil; }
public init(_ val: Int) {
self.val = val; self.next = nil; }
public init(_ val: Int, _ next: ListNode12?) {
self.val = val; self.next = next; }
}
边栏推荐
- 搜索与推荐那些事儿
- Echart 心得 (一): 有关Y轴yAxis属性
- [nilm] non intrusive load decomposition module nilmtk installation tutorial
- Upgrade Mysql to the latest version (mysql8.0.25)
- [run the script framework in Django and store the data in the database]
- Keep one decimal place and two decimal places
- Learning event binding of 3D visualization from scratch
- VsCode主题推荐
- 基金的募集,交易与登记
- Saccadenet: use corner features to fine tune the two stage prediction frame | CVPR 2020
猜你喜欢

Model effect optimization, try a variety of cross validation methods (system operation)

Graphmae ---- quick reading of papers

Simple summary of lighting usage

Vulnhub靶机:BOREDHACKERBLOG_ CLOUD AV

Swift 基础 Swift才有的特性

SVN实测常用操作-记录操作大全

Coordinate transformation of graphic technology
![[nilm] non intrusive load decomposition module nilmtk installation tutorial](/img/d0/bc5ea1cbca9ee96a2fe168484ffec4.png)
[nilm] non intrusive load decomposition module nilmtk installation tutorial

2022 PMP project management examination agile knowledge points (1)

2022茶艺师(中级)上岗证题库及在线模拟考试
随机推荐
软件工程导论——第二章——可行性研究
Learning event binding of 3D visualization from scratch
Analysis of abnormal problems in domain name resolution in kubernetes
Backup and restore SQL Server Databases locally
Case examples of corpus data processing (cases related to sentence retrieval)
Future trends in automated testing
"Adobe international certification" about Adobe Photoshop, creating and modifying brush tutorials?
1-4metaploitable2 introduction
How does dating software cut your leeks
Industrial computer anti cracking
51单片机_外部中断 与 定时/计数器中断
Redolog and binlog
Optimization and practice of Tencent cloud EMR for cloud native containerization based on yarn
解决笔记本键盘禁用失败问题
Oracle advanced SQL qualified query
Question 1: the container that holds the most water
Introduction to software engineering - Chapter 3 - Requirements Analysis
C# Lambda
UTC、GMT、CST
Écouter le réseau d'extension SWIFT (source)