47. Permutations II

class Solution(object):
    def permuteUnique(self, nums):
        """
        :type nums: List[int]
        :rtype: List[List[int]]
        """
        def permute (res,nums,perm):
            if not nums:
                res.append(perm[:])
            for i in xrange(len(nums)):
                if (i==0 or nums[i]!=nums[i-1]):
                    perm.append(nums[i])
                    permute(res,nums[:i]+nums[i+1:],perm)
                    perm.pop()
            
        res=[]
        perm=[]
        permute(res,sorted(nums),perm)
        return res

你可能感兴趣的:(47. Permutations II)