def multi_merge_v1(lst_of_lsts):
all = [e for lst in lst_of_lsts for e in lst]
merged = []
while all != []:
minimum = min(all)
merged += [minimum]
all.remove(minimum)
return merged
此代码的时间复杂度是多少?是O(2mn)?因为创建“所有”需要mn步骤,同时需要mn步骤
答案 0 :(得分:1)
O((m*n)**2)
因为while
循环执行m*n
次而min(all)
,all.remove(minimum)
是O(n*m)
次操作。