Skip to content

Commit a1a3762

Browse files
authored
Create 1863. Sum of All Subset XOR Totals (#483)
2 parents 4ae750e + 3ff09f1 commit a1a3762

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

1863. Sum of All Subset XOR Totals

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
int subsetXORSum(vector<int>& a) {
4+
int n = a.size();
5+
int bitSize = 1 << n;
6+
int res = 0;
7+
for(int i=0;i<bitSize;i++) {
8+
int curr = 0;
9+
for(int j=0;j<n;j++) {
10+
if(i & (1<<j)) {
11+
curr^=a[j];
12+
}
13+
}
14+
res+=curr;
15+
}
16+
return res;
17+
}
18+
};

0 commit comments

Comments
 (0)