华为笔试题:获取字符串无重复排列组合数量

华为笔试题:获取字符串无重复排列组合数量

获取字符串无重复排列组合数量,例如:baac,无重复排列组合数量为12

#获取字符串无重复排列组合数量。

def rank(str1):
    list1 = []
    a = 1
    b = 1
    c = 1
    for i in range(0,len(str1)):
        if str1[i] in list1:
            a += 1
            continue
        else:
            list1.append(str1[i])
    for m in range(1,len(str1)+1):
        b=b*m
    for n in range(1,a+1):
        c=c*n
    return b/c

result = rank("agarer")
print(result)

120.0

猜你喜欢

转载自blog.csdn.net/zx980414k/article/details/108840204