class Solution:
def permute(self, nums: List[int]) -> List[List[int]]:
res = []
visited = set([])
candi = []
def dfs():
if len(candi) == len(nums):
res.append(candi.copy())
return
for i in range(len(nums)):
if i in visited:
continue
visited.add(i)
candi.append(nums[i])
dfs()
visited.remove(i)
candi.remove(nums[i])
dfs()
return res