Algorithms/Medium
47. Permutations II (Medium Level)
반응형
def dfs(nums, n, skip, perm, res): if len(perm) == n: res.add(tuple(perm[:])) return for i in range(n): if skip[i] == True: continue skip[i] = True perm += nums[i], dfs(nums, n, skip, perm, res) perm.pop() skip[i] = False n = len(nums) res = set() dfs(nums, n, [False]*n, [], res) return list(res) |
반응형
댓글