Re: [闲聊] 每日leetcode

楼主: dont   2024-11-08 19:30:16
1829. Maximum XOR for Each Query
## 思路
先对整个nums阵列做XOR
k = xor ^ mask (11111111)
for loop纪录k并更新xor值
## Code
```python
class Solution:
def getMaximumXor(self, nums: List[int], maximumBit: int) -> List[int]:
n = len(nums)
xor = 0
for num in nums:
xor ^= num
res = []
mask = (1 << maximumBit) - 1
for i in range(n-1, -1, -1):
res.append(xor ^ mask)
xor ^= nums[i]
return res
```
作者: oin1104 (是oin的说)   2024-11-08 19:49:00
大师

Links booklink

Contact Us: admin [ a t ] ucptt.com