ほぼ日刊競プロ leetcode 46. Permutations
46. Permutations
Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order.
考えたこと
配列が与えられるので,順列を生成し返せばよい.pythonにはitertoolsを使えば組み合わせや順列を生成できるので,それを使う.
import itertools
class Solution:
def permute(self, nums: List[int]) -> List[List[int]]:
ans = []
for v in itertools.permutations(nums):
print(v)
ans.append(v)
return ans