링크
순열 구하는 코드
def permute(self, nums: List[int]) -> List[List[int]]:
return list(itertools.permutations(nums))
def permute(self, nums: List[int]) -> List[List[int]]:
ans = []
def dfs(arr, check):
if len(arr) == len(nums):
ans.append(arr)
return
for i in range(len(nums)):
if not check[i]:
check[i] = 1
dfs(arr + [nums[i]], check)
check[i] = 0
dfs([], [0] * len(nums))
return ans
def permute(self, nums: List[int]) -> List[List[int]]:
ans = []
def dfs(per, arr):
if len(per) == len(nums):
ans.append(per)
return
for i in range(len(arr)):
dfs(per + [arr[i]], arr[:i] + arr[i+1:])
dfs([], nums)
return ans