码迷,mamicode.com
首页 > 其他好文 > 详细

【剑指offer】Q17:合并两个排序的链表

时间:2014-07-08 18:46:04      阅读:227      评论:0      收藏:0      [点我收藏+]

标签: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

【剑指offer】Q17:合并两个排序的链表

标签:algorithm   面试题   python   merge   合并   

原文地址:http://blog.csdn.net/shiquxinkong/article/details/37327627

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!