my python weird solution, could anyone help explain?


  • 0
    J
    def permute(nums):
        res = []
        nums.sort()
        arr = [[nums[0]]]
        for i in range(1,len(nums)):
            j = 0
            while j < i+1:
                for k in range(len(arr)):
                    res += [arr[k][:j] + [nums[i]] + arr[k][j:]] 
                j+=1
            arr,res = res, []
        return arr
    

Log in to reply
 

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