LeetCode 1829. Maximum XOR for Each Query in F#
URL
Maximum XOR for Each Query - LeetCode
Code
let getMaximumXor (nums: int list) (maximumBit: int) : int list =
let rec getMaximumXor' nums xor mask acc =
match nums with
| [] -> acc
| h :: t ->
let xor = xor ^^^ h
let answer = ~~~xor &&& mask
getMaximumXor' t xor mask (answer :: acc)
let mask = (1 <<< maximumBit) - 1
getMaximumXor' nums 0 mask []