Simple python solution using sets (5 lines)

  • 0
        def subsetsWithDup(self, nums):
            res = {()}
            for num in sorted(nums):
                for item in res.copy():
            return [list(item) for item in res]

    Note: It seems converting tuples to list and back on 3rd line might make it a bit faster:


Log in to reply

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