classSolution:defpermutation(self,s:str) -> List[str]: chars, n =list(s),len(s)if n ==0:return [] res = []defdfs(index):if index == n -1:# 遍历到了最后一个字符 res.append(''.join(chars))return seen =set()for i inrange(index, n):if chars[i]in seen:continue chars[index], chars[i]= chars[i], chars[index] seen.add(chars[index])dfs(index +1) chars[index], chars[i]= chars[i], chars[index]dfs(0)return res