标签:algorithm 面试题 python merge 合并
def Merge(head1, head2): if head1 == None: return head2 if head2 == None: return head1 psuhead = ListNode(-1) tail = psuhead while head1 and head2: if head1.val < head2.val: cur = head1 head1 = head1.next else: cur = head2 head2 = head2.next cur.next = tail.next tail.next = cur tail = cur Print(psuhead) # link the rest nodes if head1 == None: head1 = head2 tail.next = head1 head1 = psuhead.next del psuhead psuhead = None return head1
【剑指offer】Q17:合并两个排序的链表,布布扣,bubuko.com
标签:algorithm 面试题 python merge 合并
原文地址:http://blog.csdn.net/shiquxinkong/article/details/37327627