Python


  • 0

    Actually this is only a Python version of this solution!

    class Solution(object):
        def subsetsWithDup(self, nums):
            nums.sort()
            ans, idx, cnt = [[]], 0, 1
            while idx < len(nums):
                while idx + 1 < len(nums) and nums[idx + 1] == nums[idx]:
                    idx, cnt = 1 + idx, cnt + 1
                tmp = ans[:]
                for e in tmp:
                    for i in xrange(1, cnt + 1):
                        ans.append( e  + ( [ nums[idx] ] * i))
                idx, cnt = idx + 1, 1
            return ans
    

Log in to reply
 

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