My accepted python code using DSF


  • 0
    S
    def permute(self, nums):
        """
        :type nums: List[int]
        :rtype: List[List[int]]
        """
        if len(nums) == 0:
            return [[]]
        if len(nums) == 1:
            return [nums]
        nums.sort()
        results = []
        solution = []
        results = self.mypermute(nums,solution, results)
        return results
    
    def mypermute(self, nums,solution, results):
        if len(nums) == 1:
            solution += nums
            results.append(solution)
            return results
        for i in range(len(nums)):
            temp = copy.copy(nums)
            temp.remove(nums[i])
            results = self.mypermute(temp, solution + [nums[i]], results )
        return results

Log in to reply
 

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