当前位置:网站首页>剑指 Offer 25. 合并两个排序的链表
剑指 Offer 25. 合并两个排序的链表
2022-07-20 19:51:00 【愈努力俞幸运】
剑指 Offer 25. 合并两个排序的链表https://leetcode.cn/problems/he-bing-liang-ge-pai-xu-de-lian-biao-lcof/
设置两个指针,一个指向第一个链表,第二个指向第二个列表,然后比较大小关系,交替前进即可。
python三元表达式的写法
Python 三元表达式写法 A if x else B
,代表当 x = Truex 时执行 AA ,否则执行 BB 。
class Solution:
def mergeTwoLists(self, l1, l2):
if not l1:return l2
if not l2: return l1
cur=l1
if l1.val <= l2.val:
cur= l1
l1 = l1.next
else:
cur = l2
l2 = l2.next
res = cur
while l1 and l2:
if l1.val<=l2.val:
cur.next,l1=l1,l1.next
else:
cur.next, l2 = l2, l2.next
cur=cur.next
if l1:
cur.next=l1
if l2:
cur.next = l2
return res
边栏推荐
- How to solve the problem that win11 excel file becomes a whiteboard icon?
- Multi active architecture of King glory mall
- 静态库制作及使用
- 2022年7月俄罗斯数据库排行榜:ClickHouse雄踞榜首,GigaBASE摘得榜眼
- Win11 22H2怎么卸载更新补丁?Win11 22H2卸载更新补丁的步骤
- APR学习失败问题定位排查
- 乌卡时代下,企业供应链如何敏捷应对企业采购支出管理?
- How to uninstall the update patch for win11 22h2? Steps to uninstall the updated patch for win11 22h2
- How to test wechat applet
- 华为云:一切皆服务,共建全场景智慧金融
猜你喜欢
随机推荐
乌鲁木齐申万宏源证券开户怎么样,安全吗?
The computer suddenly shows that there is only C disk, and other disks do not show ---- solution (very simple)
利用dump文件反向定位崩溃位置的体会
redis6.0集群搭建
搭建简易动态ip代理池
The White House is trying to promote the filling of hundreds of thousands of cyber security jobs in the United States
In the era of UCA, how can the enterprise supply chain respond to the enterprise procurement expenditure management quickly?
One bite of Stream(7)
STL notes (XIII): relevance container - mapping
带新人心得
yarn资源管理器小结
Rt-thread-2022 summer camp - learning summary - day 3 (thread synchronization)
One bite of Stream(6)
mysqladmin、mysqldump、mysqlslap、mysqlshow、mysqlcheck 客户机程序的用途
PostgreSQL operation and maintenance - distributed citus single machine multi instance deployment
Is it OK to open an account with flush? Is it safe?
乘数科技云管控平台适配阿里云PolarDB,共促云原生数据库生态繁荣
How to test wechat applet
快手海外产品 SnackVideo 与 PUBG MOBILE 独家合作 助力手游海外破圈
Is it safe to open an account in flush? How much commission can you give?