Posted on

Description

Submission

class Solution {
public:
    vector<vector<int>> subsetsWithDup(vector<int>& nums) {
        int n = nums.size();

        sort(nums.begin(), nums.end());

        set<vector<int>> rets;
        for(int state = 0; state < (1<<n); ++state) {
            vector<int> hand;
            for(int i = 0; i < n; ++i) {
                if((state>>i)&1) hand.push_back(nums[i]);
            }
            rets.insert(hand);
        }

        return {rets.begin(), rets.end()};
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *