[tag] DFS, permutation
class Solution:
def permute(self, nums: List[int]) -> List[List[int]]:
num_set = set()
temp = []
ans = []
def dfs():
if len(temp) == len(nums):
ans.append(temp.copy())
for i in range(0, len(nums)):
if i not in num_set:
temp.append(nums[i])
num_set.add(i)
dfs()
num_set.remove(i)
temp.pop()
dfs()
return ans