Python Simple Solution


  • 0
    R
    import copy
    class Solution(object):
        def __init__(self):
            self.res = []
    
        def rec(self, nums, i, n):
            if i==n :
                if not(copy.copy(nums) == self.res):
                    self.res.append(copy.copy(nums))
                return
            j = i
            while(j < n):
                aux = nums[j]
                nums[j] = nums[i]
                nums[i] = aux
                self.rec(nums, i+1, n)
                aux = nums[j]
                nums[j] = nums[i]
                nums[i] = aux
                j = j + 1
    
        def permute(self, nums):
            res = []
            self.rec(nums, 0, len(nums))
            return self.res
    

Log in to reply
 

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