【发布时间】:2020-11-12 18:09:27
【问题描述】:
我正在做一些初学者 python 作业,这个野蛮的问题突然出现,我花了很多时间研究,但我没有发现任何有用的东西,但我觉得答案可能比什么更简单'到目前为止发现。 练习:
# 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.
# The solution should work in "linear" time, making a single
# pass of both lists.
# Hint: Don't use `sort` or `sorted` -- they are not O(n)
# linear time and the two lists are already provided in
# ascending sorted order.
如果您能提供一些有关该主题的文档,我将不胜感激,谢谢。
【问题讨论】:
-
在归并排序算法中查找归并步骤
-
这是“合并排序”中的“合并”操作。
i是一个列表中的位置,j是另一个列表中的位置。两者都从0开始。每次“获取”一个元素时,都会增加位置。在您到达一个列表的末尾后,您可以从另一个列表中获取所有内容。 -
已经在 stackoverflow 中讨论过
标签: python python-3.x algorithm sorting