Advertisement
Josif_tepe

Untitled

Feb 13th, 2024
1,086
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. vector<vector<int>> subsets(vector<int>& nums) {
  2.     int n = (int) nums.size();
  3.     vector<vector<int>> subsets;
  4.     for(int bitmask = 0; bitmask < (1 << n); bitmask++) {
  5.         vector<int> subset;
  6.         for(int bit = 0; bit < n; bit++) {
  7.             if(bitmask & (1 << bit)) {
  8.                 subset.push_back(nums[bit]);
  9.             }
  10.         }
  11.         subsets.push_back(subset);
  12.     }
  13.    
  14.     return subsets;
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement