题目描述:
给定一个只包含大写英文字母的字符串S,要求你给出对S重新排列的所有不相同的排列数。
如:S为ABA,则不同的排列有ABA、AAB、BAA三种。
解答要求
时间限制:5000ms, 内存限制:100MB
输入描述
输入一个长度不超过10的字符串S,确保都是大写的。
输出S重新排列的所有不相同的排列数(包含自己本身)。
示例 1:
#解题1:排列首先想到itertools模块
import itertools
from itertools import combinations,permutations
#permutations 连续返回由 iterable 元素生成长度为 r 的排列
s=input().upper()
new=[]
for i in permutations(s,len(s)):
if i not in new:
new.append(i)
print(len(new))
#但是长度过大 不满足运行时间(需要修改算法)
修改算