We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 34b73c7 commit ecab2adCopy full SHA for ecab2ad
Math/3681.Maximum-XOR-of-Subsequences/3681.Maximum-XOR-of-Subsequences.cpp
@@ -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