Skip to content

Commit 17c890a

Browse files
committed
Time: 2 ms (100.00%), Space: 58.5 MB (81.61%) - LeetHub
1 parent 06086c5 commit 17c890a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public int[] getMaximumXor(int[] nums, int maximumBit) {
3+
int xor = 0, n = nums.length;
4+
int max = (1 << maximumBit) - 1;
5+
int res[] = new int[n];
6+
7+
for(int e : nums) xor ^= e;//xor all elements
8+
9+
for(int i = 0; i < n; i++){
10+
res[i] = xor ^ max;// k = xor ^ max
11+
xor ^= nums[n - i - 1];//remove last element from xor
12+
}
13+
return res;
14+
}
15+
}

0 commit comments

Comments
 (0)