46.全排列
- class Solution(object):
- def permute(self, nums):
- """
- :type nums: List[int]
- :rtype: List[List[int]]
- """
- # 结果数组0
- ans=[]
- n=len(nums)
- # 判断是否使用
- state_=[False]*n
- # 临时状态数组
- dp_=[]
-
-
- def dfs (index):
- # 终止条件
- if index==n:
- ans.append(dp_[:])
- return
- for i in range (n):
- if not state_[i]:
- state_[i]=True
- dp_.append(nums[i])
- dfs(index+1)
- dp_.pop()
- state_[i]=False
- dfs(0)
- return ans