46.全排列-py
46.全排列
class Solution(object):def permute(self, nums):""":type nums: List[int]:rtype: List[List[int]]"""# 结果数组0ans=[]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]=Truedp_.append(nums[i])dfs(index+1)dp_.pop()state_[i]=Falsedfs(0)return ans