My Python Solution


  • 0
    J
    class Solution(object):
    def permuteUnique(self, nums):
        res = []
        vis = [0] * len(nums)
        self.getNextPermute(nums,0,res)
        return res
    
    def getNextPermute(self, nums, id, res):
        if id == len(nums) - 1:
            res.append(nums[:])
            return
        for i in range(id,len(nums)):
            if (i == id or (nums[i] not in nums[id:i])) :
                (nums[id],nums[i]) = (nums[i], nums[id])
                self.getNextPermute(nums,id+1,res)
                (nums[id],nums[i]) = (nums[i], nums[id])
        return

Log in to reply
 

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