当前位置:网站首页>Leetcode-21 combines two ordered linked lists
Leetcode-21 combines two ordered linked lists
2022-07-01 18:47:00 【It was the sea】
# 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
边栏推荐
- Rust language - cargo, crates io
- 如何运营好技术相关的自媒体?
- [noip2015] jumping stone
- NSI packaging script add file details
- Navicat premium 15 permanent cracking and 2021 latest idea cracking (valid for personal testing)
- Force buckle day33
- Principal component calculation weight
- Leetcode-160相交链表
- 每周推荐短视频:警惕“现象”与“问题”相互混淆
- Roll out! Enlightenment!
猜你喜欢
Salesmartly has some tricks for Facebook chat!
Leetcode-128 最长连续序列
Solution: you can ping others, but others can't ping me
Basic concepts of binary tree
1、《创建您自己的NFT集合并发布一个Web3应用程序来展示它们》什么是NFT
主成分之综合竞争力案例分析
[today in history] February 15: Pascal's father was born; YouTube was founded; Kotlin language comes out
Lumiprobe 双功能交联剂丨Sulfo-Cyanine5 双-NHS 酯
AI 训练速度突破摩尔定律;宋舒然团队获得RSS 2022最佳论文奖
LeetCode 148. Sort linked list
随机推荐
Lumiprobe bifunctional crosslinker sulfo cyanine 5 bis NHS ester
What impact will multinational encryption regulation bring to the market in 2022
Operating system interview assault
R language uses the aggregate function of epidisplay package to divide numerical variables into different subsets based on factor variables, and calculate the summary statistics of each subset
主成分计算权重
After studying 11 kinds of real-time chat software, I found that they all have these functions
What if the reliability coefficient is low? How to calculate the reliability coefficient?
Lumiprobe 双功能交联剂丨Sulfo-Cyanine5 双-NHS 酯
[noip2015] jumping stone
Halcon image calibration enables subsequent image processing to become the same as the template image
[source code analysis] NVIDIA hugectr, GPU version parameter server - (1)
A wonderful time to buy and sell stocks
Basic concepts of binary tree
C# SelfHost WebAPI (2)
How to find the optimal learning rate
Search 2D matrix 2
隐私沙盒终于要来了
R语言ggplot2可视化:gganimate创建动态柱状图动画(gif)、在动画中沿给定维度逐步显示柱状图、enter_grow函数和enter_fade函数控制运动内插退出(渐变tweening)
Salesmartly has some tricks for Facebook chat!
R语言使用epiDisplay包的tableStack函数制作统计汇总表格(基于目标变量分组的描述性统计、假设检验等)、不设置by参数则计算数据框指定数据列范围的基础描述性统计信息