python 字符串(y有重复)全排列算法

def Permutation(str, beg, endl):
    if beg == endl - 1:
        print(str)
        return
    for i in range(beg, endl):
        if str[i] in str[beg:i]:
            continue

        str[i], str[beg] = str[beg], str[i]
        Permutation(str, beg+1, endl)
        str[beg], str[i] = str[i], str[beg]


a = '1223'
a = list(a)
beg = 0
endl = len(a)
Permutation(a, beg, endl)

你可能感兴趣的:(算法,python)