1829. Maximum XOR for Each Query

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1829

class Solution:
    def getMaximumXor(self, nums: List[int], maximumBit: int) -> List[int]:
        res = []
        xs = reduce(xor, nums)
        mask = (1 << maximumBit) - 1
        for x in nums[::-1]:
            k = xs ^ mask
            res.append(k)
            xs ^= x
        return res