Skip to content

Commit 5cacae4

Browse files
authored
Create 2044. Count Number of Maximum Bitwise-OR Subsets (#612)
2 parents 42278a9 + e7458e4 commit 5cacae4

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public:
3+
int countMaxOrSubsets(vector<int>& nums) {
4+
int mx_or = 0, n = nums.size();
5+
for(int x: nums) mx_or |= x;
6+
7+
int total_subsets = pow(2, n)-1;
8+
9+
int cnt = 1;
10+
for(int i=1;i<total_subsets; i++) {
11+
int or_sub = 0;
12+
for(int j=0;j<n;j++) {
13+
int x = 1<<j;
14+
if(x&i) or_sub |= nums[j];
15+
}
16+
if(or_sub==mx_or) ++cnt;
17+
}
18+
19+
return cnt;
20+
}
21+
};

0 commit comments

Comments
 (0)