Skip to content

Commit

Permalink
Create main.java
Browse files Browse the repository at this point in the history
  • Loading branch information
Alisherka7 authored Nov 8, 2024
1 parent a6bf71a commit 48ff62f
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions 1829. Maximum XOR for Each Query/main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Solution {

public int[] getMaximumXor(int[] nums, int maximumBit) {
int xorProduct = 0;
for (int i = 0; i < nums.length; i++) {
xorProduct = xorProduct ^ nums[i];
}
int[] ans = new int[nums.length];

int mask = (1 << maximumBit) - 1;

for (int i = 0; i < nums.length; i++) {
ans[i] = xorProduct ^ mask;
// remove last element
xorProduct = xorProduct ^ nums[nums.length - 1 - i];
}

return ans;
}
}

0 comments on commit 48ff62f

Please sign in to comment.