Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- vector<vector<int>> subsetsWithDup(vector<int>& nums) {
- int n = (int) nums.size();
- vector<vector<int>> subsets;
- set<vector<int>> st;
- for(int bitmask = 0; bitmask < (1 << n); bitmask++) {
- vector<int> subset;
- for(int bit = 0; bit < n; bit++) {
- if(bitmask & (1 << bit)) {
- subset.push_back(nums[bit]);
- }
- }
- sort(subset.begin(), subset.end());
- st.insert(subset);
- }
- for(vector<int> v : st) {
- subsets.push_back(v);
- }
- return subsets;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement