All Permutations (Laicode DFS)

class Solution(object): def helper(self, set, chosen, res): if (len(chosen) == len(set)): res.append(chosen) return for i in set: if i in chosen: continue else: # choose chosen = chosen + i # explore self.helper(set, chosen, res) # unchoose chosen = chosen[:-1] def permutations(self, set): """ input: string set return: string[] """ # write your solution here if (len(set) == 0): return set res = [] chosen = "" self.helper(set, chosen, res) return res
Note manipulate string.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.