[LeetCode] Maximum XOR After Operations

2317. Maximum XOR After Operations

You are given a 0-indexed integer array nums. In one operation, select any non-negative integer x and an index i, then update nums[i] to be equal to nums[i] AND (nums[i] XOR x).

Note that AND is the bitwise AND operation and XOR is the bitwise XOR operation.

Return the maximum possible bitwise XOR of all elements of nums after applying the operation any number of times.

1
2
3
4
5
6
class Solution {
public:
int maximumXOR(vector<int>& A) {
return accumulate(begin(A), end(A), 0, [](int bit, int a) { return bit | a; });
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2022/06/26/PS/LeetCode/maximum-xor-after-operations/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.