Advertisement
Josif_tepe

Untitled

Feb 13th, 2024
1,167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. class Solution {
  2. public:
  3.    vector<vector<int>> subsetsWithDup(vector<int>& nums) {
  4.     int n = (int) nums.size();
  5.     vector<vector<int>> subsets;
  6.     set<vector<int>> st;
  7.     for(int bitmask = 0; bitmask < (1 << n); bitmask++) {
  8.         vector<int> subset;
  9.         for(int bit = 0; bit < n; bit++) {
  10.             if(bitmask & (1 << bit)) {
  11.                 subset.push_back(nums[bit]);
  12.             }
  13.         }
  14.         sort(subset.begin(), subset.end());
  15.         st.insert(subset);
  16.     }
  17.     for(vector<int> v : st) {
  18.         subsets.push_back(v);
  19.     }
  20.     return subsets;
  21. }
  22. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement