Easy DFS python solution


  • 1
    C
    def permute(self, nums):
        """
        :type nums: List[int]
        :rtype: List[List[int]]
        """
        def dfs(nums,level,path,res):
            if level == 0:
                res.append(path)
                return
            for i in range(0,len(nums)):
                if nums[i] not in path:
                    dfs(nums,level-1,path+[nums[i]],res)
        res =[]
        dfs(nums,len(nums),[],res)
        return res

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.