Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Easy Code for Solution 2 in Question 1829.Maximum XOR for Each Query #4003

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
piyushlasane wants to merge 2 commits into doocs:main from piyushlasane:patch-1
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions solution/1800-1899/1829.Maximum XOR for Each Query/README_EN.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -303,20 +303,16 @@ class Solution:
```java
class Solution {
public int[] getMaximumXor(int[] nums, int maximumBit) {
int xs = 0;
for (int x : nums) {
xs ^= x;
int xor = (int)(Math.pow(2, maximumBit))-1;
int[] answer = new int[nums.length];
for(int i = 1; i < nums.length; i++){
nums[i] ^= nums[i-1];
}
int mask = (1 << maximumBit) - 1;
int n = nums.length;
int[] ans = new int[n];
for (int i = 0; i < n; ++i) {
int x = nums[n - i - 1];
int k = xs ^ mask;
ans[i] = k;
xs ^= x;
int k=0;
for(int i=nums.length-1; i>=0; i--){
answer[k++] ^= nums[i]^xor;
}
return ans;
return answer;
}
}
```
Expand Down

AltStyle によって変換されたページ (->オリジナル) /