# -*- coding:utf-8 -*-
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
# 返回合并后列表
def Merge(self, pHead1, pHead2):
# write code here
if not pHead1:
return pHead2
if not pHead2:
return pHead1
p=cur=ListNode(0)
while pHead1 and pHead2:
if pHead1.val >= pHead2.val:
cur.next = pHead2
pHead2 = pHead2.next
else:
cur.next = pHead1
pHead1 = pHead1.next
cur=cur.next
if pHead1:
cur.next = pHead1
elif pHead2:
cur.next = pHead2
return p.next
剑指offer-合并两个排序的链表(python)
最新推荐文章于 2021-02-16 10:25:07 发布