快速排序 O(n)空间复杂度

leetcode

python快速排序:

def quickSort(num):

    if num.__len__() < 2:

        return num

    left,right = [],[]

    base = num.pop()

    for val in num:

        if val < base:

            left.append(val)

        else:

            right.append(val)

    return quickSort(left)+[base]+quickSort(right)


    

猜你喜欢

转载自blog.csdn.net/qq_26890109/article/details/80731525