[LeetCode] Find Xor-Beauty of Array

2527. Find Xor-Beauty of Array

You are given a 0-indexed integer array nums.

The effective value of three indices i, j, and k is defined as ((nums[i] | nums[j]) & nums[k]).

The xor-beauty of the array is the XORing of the effective values of all the possible triplets of indices (i, j, k) where 0 <= i, j, k < n.

Return the xor-beauty of nums.

1
2
3
4
5
6
7
8
class Solution {
public:
int xorBeauty(vector<int>& nums) {
int res = 0;
for(auto n : nums) res ^= n;
return res;
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2023/02/07/PS/LeetCode/find-xor-beauty-of-array/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.