https://leetcode.com/problems/merge-two-sorted-lists/
先试了试判断排序:
def mergeTwoLists(self, l1, l2):
l = []
while l1 and l2:
if l1.val <= l2.val:
l.append(l1.val)
l1 = l1.next
else:
l.append(l2.val)
l2 = l2.next
while l1:
l.append(l1.val)
l1 = l1.next
while l2:
l.append(l2.val)
l2 = l2.next
return l
然后72ms
然后无聊想看看暴力读取然后排序:
def mergeTwoLists(self, l1, l2):
l = []
while l1:
l.append(l1.val)
l1 = l1.next
while l2:
l.append(l2.val)
l2 = l2.next
l.sort()
return l
居然还是72ms……
2015年6月25日
订阅:
博文评论 (Atom)
没有评论:
发表评论