题目描述:
代码:
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution(object):
def mergeTwoLists(self, l1, l2):
merValue=ListNode(0)
head=merValue
while l1 != None or l2 != None:
if l1==None:
head.next=l2
head=head.next
l2=l2.next
elif l2==None:
head.next=l1
head=head.next
l1=l1.next
else:
if l1.val<l2.val:
head.next=l1
head=head.next
l1=l1.next
else:
head.next=l2
head=head.next
l2=l2.next
return merValue.next