90. Subsets II

use backtracking
class Solution(object):
    def subsetsWithDup(self, nums):
        """
        :type nums: List[int]
        :rtype: List[List[int]]
        """
        def subsetsWithDub(res,nums,curr,begin):
            res.append(curr[:])
            for i in xrange(begin,len(nums)):
                if (i==begin or nums[i]!=nums[i-1]):
                    curr.append(nums[i])
                    subsetsWithDub(res,nums,curr,i+1)
                    curr.pop()
                    
        res=[]
        curr=[]
        subsetsWithDub(res,sorted(nums),curr,0)
        return res
       

你可能感兴趣的:(90. Subsets II)