python leetcode 46. Permutations

每个元素无重复无难度,DFS

class Solution(object):
    def permute(self, nums):
        """
        :type nums: List[int]
        :rtype: List[List[int]]
        """
        self.res=[]
        def dfs(nums,tmp):
            if len(nums) == len(tmp):
                self.res.append(tmp[:])
            for m in nums:
                if m in tmp:
                    continue 
                tmp.append(m)
                dfs(nums,tmp)
                tmp.remove(m)
        dfs(nums,[])
        return self.res

猜你喜欢

转载自blog.csdn.net/Neekity/article/details/84874959