class Solution(object):
def subsetsWithDup(self, nums):
"""
:type nums: List[int]
:rtype: List[List[int]]
"""
self.res = []
self.old = None
self.res.append([])
# for i in range(len(nums)):
nums = sorted(nums)
self.generateSub(nums, 0, [])
print self.res
return self.res
def generateSub(self, nums, start, ans):
if ans:
self.res.append(ans[0:])
for i in range(start, len(nums)):
if self.old != nums[i]:
ans.append(nums[i])
self.generateSub(nums, i + 1, ans)
self.old = ans.pop()
else:
continue
s = Solution()
nums = [1,2,2]
s.subsetsWithDup(nums)