h回溯算法
class Solution: def permutation(self, S: str) -> List[str]: def bfs(cur_list): next_list = [] for cur in cur_list: cur_str, last= cur for i in range(len(last)): next_list.append((cur_str+last[i], last[:i]+last[i+1:])) if next_list: return bfs(next_list) return [cur_str for cur_str, last in cur_list] return list(set(bfs([('', S)])))