h回溯算法

1、面试题 08.08. 有重复字符串的排列组合

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)])))

  

posted @ 2020-12-09 20:34  哈哈哈喽喽喽  阅读(142)  评论(0编辑  收藏  举报