标签:规则 nod 合成 odi 题目 描述 next ext list
题目描述
输入两个单调递增的链表,输出两个链表合成后的链表,当然我们需要合成后的链表满足单调不减规则。
python solution:
# -*- coding:utf-8 -*-
class ListNode:
def __init__(self, x):
self.val = x
self.next = None
class Solution:
# 返回合并后列表
def Merge(self, pHead1, pHead2):
new = ListNode(0)
work = new
while pHead1 and pHead2:
if pHead1.val<pHead2.val:
work.next = pHead1
work = work.next
pHead1 = pHead1.next
else:
work.next = pHead2
work = work.next
pHead2 = pHead2.next
if pHead1:
work.next = pHead1
if pHead2:
work.next = pHead2
return new.next
标签:规则 nod 合成 odi 题目 描述 next ext list
原文地址:https://www.cnblogs.com/bernieloveslife/p/10423500.html