class Solution:
def permute(self, nums: List[int]) -> List[List[int]]:
self.res = []
choice = nums[:]
# print(choice)
self.drawback(0, nums[:], choice)
return self.res
def drawback(self, i, nums, choice): # 确定第i位的位置
if i == len(nums):
self.res.append(nums)
return
for n in choice: # 第i个位置的选择有len(nums)种
nums[i] = n
check = choice[:]
check.remove(n)
# print(check)
self.drawback(i+1, nums[:], check[:])
nums[i] = 1
return
力扣-46 全排列
最新推荐文章于 2023-09-08 21:36:16 发布