python 归并排序

两个列表,合并成一个有序列表

lst1 = [1, 3, 7, 9, 12]
lst2 = [4, 8, 9, 13]
lst1 = [1, 3, 7, 9, 12]
lst2 = [4, 8, 9, 13]
lst = []
i = 0
j = 0
while i < len(lst1) and j <len(lst2) :
    if lst1[i] < lst2[j] :
        lst.append(lst1[i])
        i += 1
    else :
        lst.append(lst2[j])
        j += 1
if j ==len(lst1) :
    for i in  lst2[j:] :
        lst.append(i)
else :
    for i in lst1[i:] :
        lst.append(j)
原文地址:https://www.cnblogs.com/beihan/p/9355303.html