题解 | #字符串的排列#
字符串的排列
https://www.nowcoder.com/practice/fe6b651b66ae47d7acce78ffdd9a96c7
class Solution: def Permutation(self , str1: str): s = list(str1) output = [] n = len(s) def func(first): if first == n: output.append(''.join(s)) return used = set() for i in range(first, n): if s[i] in used: # 压入集合的应该是s[i],而不是i continue used.add(s[i]) s[first], s[i] = s[i], s[first] func(first + 1) s[first], s[i] = s[i], s[first] func(0) return output