Skip to content

2527. Find Xor-Beauty of Array 👍

  • Time: $O(n)$
  • Space: $O(1)$
1
2
3
4
5
6
class Solution {
 public:
  int xorBeauty(vector<int>& nums) {
    return accumulate(nums.begin(), nums.end(), 0, bit_xor<>());
  }
};
1
2
3
4
5
class Solution {
  public int xorBeauty(int[] nums) {
    return Arrays.stream(nums).reduce((a, b) -> a ^ b).getAsInt();
  }
}
1
2
3
class Solution:
  def xorBeauty(self, nums: list[int]) -> int:
    return functools.reduce(operator.xor, nums)