当前位置:网站首页>LeetCode-21合并两个有序链表
LeetCode-21合并两个有序链表
2022-07-01 18:33:00 【原来是大海】

# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution(object):
def mergeTwoLists(self, list1, list2):
"""
:type list1: Optional[ListNode]
:type list2: Optional[ListNode]
:rtype: Optional[ListNode]
"""
chushihua = ListNode(0)
new = chushihua
while list1 and list2:
if list1.val <= list2.val:
new.next =list1
list1 = list1.next
else:
new.next = list2
list2 = list2.next
new = new.next
new.next = list1 if list1 is not None else list2
return chushihua.next
边栏推荐
- What are the legal risks of NFT brought by stars such as curry and O'Neill?
- Fix the black screen caused by iPhone system failure
- [image denoising] matlab code for removing salt and pepper noise based on fast and effective multistage selective convolution filter
- Mujoco model learning record
- Apk signature process introduction [easy to understand]
- This is the latest opportunity of the London bank trend
- Detailed explanation of ArrayList expansion
- 2、《创建您自己的NFT集合并发布一个Web3应用程序来展示它们》启动并运行您的本地环境
- Quick foundation of group theory (5): generators, Kelley graphs, orbits, cyclic graphs, and "dimensions" of groups?
- Thread forced join, thread forced join application scenarios
猜你喜欢

MySQL connection tools

Mujoco XML modeling

Cloud picture says | distributed transaction management DTM: the little helper behind "buy buy buy"

Mysql database design

创建您自己的NFT集合并发布一个Web3应用程序来展示它们(介绍)

NSI packaging script add file details

12种数据量纲化处理方式

Three.js学习-相机Camera的基本操作(了解向)

关于企业中台规划和 IT 架构微服务转型

540. Single element in ordered array / 1684 Count the number of consistent strings
随机推荐
Apk signature process introduction [easy to understand]
Cloud computing - make learning easier
ArrayList扩容详解
Pytorch crossentropyloss learning
Flex layout
MySQL + JSON = King fried
证券开户安全么,有没有什么样的危险呢
When the fixed frequency artifact falls in love with multithreading | ros2 fixed frequency topic release demo
540. Single element in ordered array
Calculation of intersection of two line segments
主成分之综合竞争力案例分析
[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
每周推荐短视频:警惕“现象”与“问题”相互混淆
必看,时间序列分析
js如何将带有分割符的字符串转化成一个n维数组
1380. Lucky number in matrix / 1672 Total assets of the richest customers
PCL learning materials
Check log4j problems using stain analysis
Roll out! Enlightenment!
Extract the compressed package file and retrieve the password