LeetCode solutions

2621. Find Xor-Beauty of Array

My accepted Python solution to LeetCode problem 2621, Find Xor-Beauty of Array, running in 3ms.

  • Difficulty: Medium
  • Python
  • Runtime 3ms
  • Memory 30.4MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 3ms, memory 30.4MB, accepted 2025-12-31.

python
class Solution:
    def xorBeauty(self, nums: List[int]) -> int:
        # The xor-beauty mathematically simplifies to XOR of all elements
        # This is because when we XOR all triplets (i,j,k) where:
        # effective_value = (nums[i] | nums[j]) & nums[k]
        # The result equals XOR of all nums
        result = 0
        for num in nums:
            result ^= num
        return result

Source