Skip to content

Commit 5adcd50

Browse files
add 1829
1 parent 85566b2 commit 5adcd50

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1829|[Maximum XOR for Each Query](https://leetcode.com/problems/maximum-xor-for-each-query/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1829.java) ||Medium|Bit Manipulation|
1112
|1828|[Queries on Number of Points Inside a Circle](https://leetcode.com/problems/queries-on-number-of-points-inside-a-circle/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1828.java) ||Medium|Math|
1213
|1827|[Minimum Operations to Make the Array Increasing](https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1827.java) ||Easy|Array, Greedy|
1314
|1823|[Find the Winner of the Circular Game](https://leetcode.com/problems/find-the-winner-of-the-circular-game/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1823.java) ||Medium|Array|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.fishercoder.solutions;
2+
3+
public class _1829 {
4+
public static class Solution1 {
5+
public int[] getMaximumXor(int[] nums, int maximumBit) {
6+
int[] result = new int[nums.length];
7+
long[] xOr = new long[nums.length];
8+
xOr[0] = nums[0];
9+
for (int i = 1; i < nums.length; i++) {
10+
xOr[i] ^= xOr[i - 1] ^ nums[i];
11+
}
12+
long maxNum = (long) Math.pow(2, maximumBit) - 1;
13+
for (int i = 0; i < nums.length; i++) {
14+
result[nums.length - i - 1] = (int) (maxNum ^ xOr[i]);
15+
}
16+
return result;
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)