当前位置:网站首页>12-- merge two ordered linked lists
12-- merge two ordered linked lists
2022-06-24 08:19:00 【JH_ Cao】
Merge two ordered lists
- The idea is simple , Not familiar with linked list writing
- Recursive thinking

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; }
}
边栏推荐
猜你喜欢

2022茶艺师(中级)上岗证题库及在线模拟考试

LabVIEW查找n个元素数组中的质数

Installation and use of selenium IDE

Ad-gcl:advantageous graph augmentation to improve graph contractual learning

More than observation | Alibaba cloud observable suite officially released

PAT 1157:校庆

2021-03-09 COMP9021第七节课笔记

Use of swift basic closure /block (source code)

The first exposure of Alibaba cloud's native security panorama behind the only highest level in the whole domain

Swift foundation features unique to swift
随机推荐
Shader common functions
os.path.join()使用过程中遇到的坑
Auto usage example
小样本故障诊断 - 注意力机制代码 - BiGRU代码解析实现
11--无重复字符的最长子串
QOpenGL显示点云文件
新准则金融资产三分类:AMC、FVOCI和FVTPL
Pagoda panel installation php7.2 installation phalcon3.3.2
Catégorie de prêt 5
将mysql的数据库导出xxx.sql,将xxx.sql文件导入到服务器的mysql中。项目部署。
Analysis of abnormal problems in domain name resolution in kubernetes
MySQL source and target table row count check
[nilm] non intrusive load decomposition module nilmtk installation tutorial
Easyplayerpro win configuration full screen mode can not be full screen why
You get in Anaconda
Ad-gcl:advantageous graph augmentation to improve graph contractual learning
Swift foundation features unique to swift
宝塔面板安装php7.2安装phalcon3.3.2
Chapter 1 overview of canvas
Pipeline concept of graphic technology