# 2527. Find Xor-Beauty of Array
###### tags: `Leetcode` `Medium` `Bit Manipulation`
Link: https://leetcode.com/problems/find-xor-beauty-of-array/description/
## 思路
```arr = [a_1, a_2, a_3, ..., a_n]```
1. (i, j, k)和(j, i, k)得到的结果是一样的 把他们xor起来就抵消掉了 所以我们只需要考虑(i, i, k)和(j, j, k)即可
2. (i, i, k)的运算结果是```(a_i|a_i)&a_k```相当于```a_i&a_k```
因此我们可以发现 其实需要计算的是```a_1&a_1 ^ a_1&a_2 ^ ... a_1&a_n ^ a_2&a_1 ^ a_2&a_2 ^... a_2&a_n ^ ... ```也就是把每一个数字和arr里面的所有数字做& 然后^起来
那么根据公式```(a1^a2) & (b1^b2) = (a1&b1) ^ (a1&b2) ^ (a2&b1) ^ (a2&b2)``` 我们只需要求出所有数字xor之后的结果即可
## Code
```java=
class Solution {
public int xorBeauty(int[] nums) {
int xor = 0;
for(int num:nums) xor ^= num;
return xor;
}
}
```