Matej Focko
437712377a
URL: https://leetcode.com/problems/maximum-xor-for-each-query/ Signed-off-by: Matej Focko <me@mfocko.xyz>
15 lines
399 B
Kotlin
15 lines
399 B
Kotlin
class Solution {
|
|
fun getMaximumXor(
|
|
nums: IntArray,
|
|
maximumBit: Int,
|
|
): IntArray {
|
|
val mask = 1.shl(maximumBit) - 1
|
|
|
|
var runningXor = nums.reduce { x, y -> x.xor(y) }
|
|
return IntArray(nums.size) { i ->
|
|
val current = runningXor.xor(mask)
|
|
runningXor = runningXor.xor(nums[nums.size - 1 - i])
|
|
current
|
|
}
|
|
}
|
|
}
|