您的位置:首页 > 其它

Leetcode 21 Merge Two Sorted Lists

2015-05-18 12:55 344 查看
class Solution:
# @param {ListNode} l1
# @param {ListNode} l2
# @return {ListNode}
def mergeTwoLists(self, l1, l2):
head=ListNode(0)
temp = head
if l1 == None: return l2
if l2 == None: return l1

while l1 and l2:
if l1.val>l2.val:
temp.next = l2; l2 = l2.next; temp = temp.next
else:
temp.next = l1; l1 = l1.next; temp = temp.next
if l1 == None: temp.next = l2
if l2 == None: temp.next = l1
return head.next
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: