给定非空的字符串,你需要进行排列,得到所有排列并删除重复项(如果存在)
例子:
* With input 'a'
* Your function should return: ['a']
* With input 'ab'
* Your function should return ['ab', 'ba']
* With input 'aabb'
* Your function should return ['aabb', 'abab', 'abba', 'baab', 'baba', 'bbaa']
排列的顺序无关紧要。
题目难度:一般
题目来源:https://www.codewars.com/kata/5254ca2719453dcc0b00027d
def permutations(string: str) -> list:
# your code here
assert sorted(permutations('a')) == ["a"]
assert sorted(permutations('ab')) == ["ab", "ba"]
assert sorted(permutations('aabb')) == ['aabb', 'abab', 'abba', 'baab', 'baba', 'bbaa']
assert sorted(permutations('ababc')) == ['aabbc', 'aabcb', 'aacbb', 'ababc', 'abacb', 'abbac', 'abbca', 'abcab', 'abcba', 'acabb', 'acbab', 'acbba', 'baabc', 'baacb', 'babac', 'babca', 'bacab', 'bacba', 'bbaac', 'bbaca', 'bbcaa', 'bcaab', 'bcaba', 'bcbaa', 'caabb', 'cabab', 'cabba', 'cbaab', 'cbaba', 'cbbaa']