题解 | #合并两个排序的链表#
合并两个排序的链表
http://www.nowcoder.com/practice/d8b6b4358f774294a89de2a6ac4d9337
def Merge(self, pHead1, pHead2):
# write code here
if pHead1==None and pHead2==None:return None
if pHead1==None:return pHead2
if pHead2==None:return pHead1
head=ListNode(0)
head.next=None
p=head
p1=pHead1
p2=pHead2
while p1 and p2:
if p1.val <=p2.val:
p.next=p1
p=p.next
p1=p1.next
else:
p.next=p2
p=p.next
p2=p2.next
if p1:
p.next=p1
elif p2:
p.next=p2
return head.next