当前位置:网站首页>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; }
}
边栏推荐
- Swift 基础 Swift才有的特性
- 首次曝光 唯一全域最高等级背后的阿里云云原生安全全景图
- transformers PreTrainedTokenizer类
- OC extension detects whether an app is installed on the mobile phone (source code)
- Swift extension chainlayout (UI chain layout) (source code)
- 解决笔记本键盘禁用失败问题
- The first exposure of Alibaba cloud's native security panorama behind the only highest level in the whole domain
- Simple summary of lighting usage
- Installation and use of selenium IDE
- jwt(json web token)
猜你喜欢

Application of JDBC in performance test

解决笔记本键盘禁用失败问题

C语言_字符串与指针的爱恨情仇

1-4metaploitable2 introduction

Utilisation de la fermeture / bloc de base SWIFT (source)

Shader common functions

2021-03-11 COMP9021第八节课笔记

Blue Bridge Cup_ Queen n problem

Swift 基础 闭包/Block的使用(源码)

1279_ Vsock installation failure resolution when VMware player installs VMware Tools
随机推荐
QOpenGL显示点云文件
OC extension detects whether an app is installed on the mobile phone (source code)
Qopengl display point cloud file
Selenium IDE的安装以及使用
Swift extension networkutil (network monitoring) (source code)
June 27, 2021: given a positive array arr, it represents the weight of several people
权限模型 DAC ACL RBAC ABAC
Four models of iPhone 13 series have been exposed, and indeed, they are 13 fragrant!
问题3 — messageBox弹框,修改默认背景色
jwt(json web token)
C语言_字符串与指针的爱恨情仇
2021-03-09 COMP9021第七节课笔记
Vulnhub target: boredhackerblog: social network
Screenshot recommendation - snipaste
Shader common functions
In the post epidemic era, the home service robot industry has just set sail
软件过程与项目管理期末复习与重点
Five level classification of loans
Introduction to software engineering - Chapter 3 - Requirements Analysis
487. 最大连续1的个数 II ●●