【发布时间】:2023-03-12 09:44:01
【问题描述】:
我有这个,它可以工作:
# E. Given two lists sorted in increasing order, create and return a merged
# list of all the elements in sorted order. You may modify the passed in lists.
# Ideally, the solution should work in "linear" time, making a single
# pass of both lists.
def linear_merge(list1, list2):
finalList = []
for item in list1:
finalList.append(item)
for item in list2:
finalList.append(item)
finalList.sort()
return finalList
# +++your code here+++
return
但是,我真的很想好好学习这些东西。 :) “线性”时间是什么意思?
【问题讨论】:
-
不,这是我在业余时间运行的 Google Python 教程。
-
你可能想看看算法,这与python无关。这称为合并。暂时忘记python,如何合并两个非单调递增的排序列表。您可以查看合并排序以更好地理解这一点。即使是插入排序也可以做到这一点,您也可以使用二进制插入。