Skip to content

Commit 95c1c5e

Browse files
authored
Create 1829. Maximum XOR for Each Query (#629)
2 parents 508d970 + bb730c1 commit 95c1c5e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

1829. Maximum XOR for Each Query

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public:
3+
vector<int> getMaximumXor(vector<int>& nums, int maximumBit) {
4+
int n = nums.size();
5+
int mx = pow(2,maximumBit)-1;
6+
vector<int> ans(n,0);
7+
int xr = 0;
8+
for(int i=0;i<n;i++)
9+
{
10+
xr ^= nums[i];
11+
ans[n-i-1] = (mx)^(xr&mx);
12+
}
13+
return ans;
14+
}
15+
};

0 commit comments

Comments
 (0)