Skip to content

Commit 81a3fa8

Browse files
committed
another alogrithm only one loop
1 parent fb3a12e commit 81a3fa8

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

algorithms/cpp/maximumXorForEachQuery/MaximumXorForEachQuery.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,21 @@
4949

5050
class Solution {
5151
public:
52+
vector<int> getMaximumXor(vector<int>& nums, int maximumBit) {
53+
54+
const int size = nums.size();
55+
const int max = (1 << maximumBit) - 1;
56+
57+
int all = 0;
58+
vector<int> result(size);
59+
for(int i = 0; i < size; i++) {
60+
all ^= nums[i];
61+
result[size-i-1] = all ^ max;
62+
}
63+
64+
return result;
65+
}
66+
5267
vector<int> getMaximumXor(vector<int>& nums, int maximumBit) {
5368
int all = 0;
5469
for(auto& n : nums) {

0 commit comments

Comments
 (0)