当前位置:网站首页>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
边栏推荐
- 主成分之综合竞争力案例分析
- Memo - about C # generating barcode for goods
- [Chongqing Guangdong education] basic psychology reference materials of Tianjin Normal University
- 搭建一個通用監控告警平臺,架構上需要有哪些設計
- R语言caTools包进行数据划分、scale函数进行数据缩放、class包的knn函数构建K近邻分类器、table函数计算混淆矩阵
- C operator overloads the query table
- Popular science: what does it mean to enter the kernel state?
- 宏观视角看抖音全生态
- NSI packaging script add file details
- Introduction to easyclick database
猜你喜欢
How does factor analysis calculate weights?
LeetCode 148. Sort linked list
用GSConv+Slim Neck改进Yolov5,将性能提升到极致!
Basic concepts of binary tree
Mysql database of easyclick
NSI packaging script add file details
Memo - about C # generating barcode for goods
斯坦福、Salesforce|MaskViT:蒙面视觉预训练用于视频预测
1380. Lucky number in matrix / 1672 Total assets of the richest customers
After studying 11 kinds of real-time chat software, I found that they all have these functions
随机推荐
Rust language - cargo, crates io
Calculation of intersection of two line segments
Blue Bridge Cup real topic: the shortest circuit
信度系数低怎么办?信度系数具体怎么算?
Regular expression
[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
Go Technology Daily (2022-02-14) - go language slice interview real questions 8 consecutive questions
Leetcode203 移除链表元素
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
期货账户的资金安全吗?怎么开户?
R语言ggplot2可视化:可视化折线图、使用labs函数为折线图添加自定义的Y轴标签信息(customize y axis label)
MySQL connection tools
Computer network interview assault
Evaluation of 6 red, yellow and black list cameras: who is the safest? Who has good picture quality? From now on, let you no longer step on thunder
Mysql database design
Using OpenSSL encryption to rebound shell traffic
Operating system interview assault
Static timing analysis (STA) in ic/fpga design
Implement a Prometheus exporter
Mise en place d'une plate - forme générale de surveillance et d'alarme, quelles sont les conceptions nécessaires dans l'architecture?