Leetcode46-全排列
思路:
代码:
class Solution:
def permute(self, nums: List[int]) -> List[List[int]]:
res = []
def backtrack(path):
if len(path) == len(nums):
res.append(path[:])
return
for i in range(len(nums)):
if nums[i] in path:
continue
else:
path.append(nums[i])
backtrack(path)
path.pop()
backtrack([])
return res