LeetCode 1829. Maximum XOR for Each Query in F#

URL

Maximum XOR for Each Query - LeetCode

Code

https://github.com/syohex/dotnet-study/tree/master/fsharp/leetcode/challenge/202411/maximum_xor_for_each_query/main.fsx

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 []