2044.cpp (486B)
1 class Solution { 2 int rec(const vector<int> &nums, const int maxi, int crnt = 0, int idx = 0) { 3 if (idx == nums.size()) return crnt == maxi; 4 if (crnt == maxi) return 1 << (nums.size() - idx); 5 return rec(nums, maxi, crnt, idx + 1) + rec(nums, maxi, crnt | nums[idx], idx + 1); 6 } 7 8 public: 9 int countMaxOrSubsets(const vector<int> &nums) { 10 int maxi = 0; 11 for (int n : nums) 12 maxi |= n; 13 return rec(nums, maxi); 14 } 15 };