Skip to content

Commit ecab2ad

Browse files
authored
Create 3681.Maximum-XOR-of-Subsequences.cpp
1 parent 34b73c7 commit ecab2ad

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public:
3+
int maxXorSubsequences(vector<int>& nums) {
4+
vector<int>basis(32, 0);
5+
for (int x: nums) {
6+
for (int i=31; i>=0; i--) {
7+
if (!(x>>i)&1) continue;
8+
if (!basis[i]) {
9+
basis[i] = x;
10+
break;
11+
}
12+
x ^= basis[i];
13+
}
14+
}
15+
16+
int ans = 0;
17+
for (int i = 31; i >= 0; i--) {
18+
ans = max(ans, ans ^ basis[i]);
19+
}
20+
return ans;
21+
}
22+
};

0 commit comments

Comments
 (0)