剑指offer-合并两个排序链表16
2024-08-28 21:52:26
题目描述
输入两个单调递增的链表,输出两个链表合成后的链表,当然我们需要合成后的链表满足单调不减规则。
class Solution:
# 返回合并后列表
def Merge(self, pHead1, pHead2):
# write code here
if pHead1==None:
return pHead2
if pHead2==None:
return pHead1
head=ListNode(-1)
head.next=None
root=head
while pHead1 is not None and pHead2 is not None:
if pHead1.val<pHead2.val:
head.next=pHead1
head=pHead1
pHead1=pHead1.next
else:
head.next=pHead2
head=pHead2
pHead2=pHead2.next
if pHead1 is None:
head.next=pHead2
else:
head.next=pHead1
return root.next
最新文章
- iOS---iOS10适配iOS当前所有系统的远程推送
- 关于input的file框onchange事件触发一次失效的新的解决方法
- I’m Sure It Will Only Take You A Few Days To Code
- IOS在线安装App
- Hybrid框架UI重构之路:五、前端那点事儿(HTML、CSS)
- php 购物车的例子
- NandFlash详述【转】
- PyPI镜像网站
- winserve2008下不能运行winXP下开发的应用程序→更改“兼容性”
- jquery初学者易犯的错误
- bzoj 2623 所罗门的咒语
- python遗产
- 在Linux与Windows上获取当前堆栈信息
- xmanager无法弹出图形化界面。
- 解决 ASP.NET Core Hangfire 未授权(401 Unauthorized)
- 【LeetCode每天一题】Set Matrix Zeroes(设置0矩阵)
- Fluentd初探 简介与安装
- vue 渲染函数&;jsx
- Hyper-v带宽限制以及验证工具
- sublime 3插件推荐