当前位置:网站首页>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
边栏推荐
- Apk signature process introduction [easy to understand]
- D. Yet Another Minimization Problem
- Is the fund of futures account safe? How to open an account?
- Domestic spot silver should be understood
- Growing up in the competition -- (Guangyou's most handsome cub) Pikachu walking
- Search 2D matrix 2
- Roll out! Enlightenment!
- Talk about the favorite tools used by project managers
- 1、《创建您自己的NFT集合并发布一个Web3应用程序来展示它们》什么是NFT
- Leetcode203 移除链表元素
猜你喜欢

必看,时间序列分析

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

Bug of QQ browser article comment: the commentator is wrong

Using OpenSSL encryption to rebound shell traffic

1、《创建您自己的NFT集合并发布一个Web3应用程序来展示它们》什么是NFT

GAMES202作业0-环境搭建过程&解决遇到的问题

Growing up in the competition -- (Guangyou's most handsome cub) Pikachu walking

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

Mujoco model learning record

Nearly 60% of the employees strongly support Ctrip's "3+2" working mode, and work at home for two days a week
随机推荐
NSI packaging script add file details
[acnoi2022] color ball
Yolov5 practice: teach object detection by hand
Check log4j problems using stain analysis
Session layer of csframework, server and client (1)
網上股票開戶安全嗎?是否可靠?
How to retrieve the password for opening Excel files
Sum of three numbers
Computer network interview assault
Is the fund of futures account safe? How to open an account?
Leetcode 1380. Lucky numbers in the matrix (save the minimum number of each row and the maximum number of each column)
Opencv map reading test -- error resolution
Sanfeng cloud 0215 I often use
Easycvr accesses the equipment through the national standard gb28181 protocol. What is the reason for the automatic streaming of the equipment?
Is Alipay wallet convenient to use?
每周推荐短视频:警惕“现象”与“问题”相互混淆
The latest software scheme of the intelligent information management system of the armed police force
期货账户的资金安全吗?怎么开户?
Domestic spot silver should be understood
Definition of rotation axis in mujoco