美文网首页
47. Permutations II

47. Permutations II

作者: 阿团相信梦想都能实现 | 来源:发表于2016-12-13 04:07 被阅读0次
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

      本文链接:https://www.haomeiwen.com/subject/sruvmttx.html