LeetCode 1310. XOR Queries of a Subarray in F#

URL

XOR Queries of a Subarray - LeetCode

Code

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

let xorQueries (arr: int list) (queries: (int * int) list) : int list =
    let rec xorQueries' queries (arr: int[]) acc =
        match queries with
        | [] -> List.rev acc
        | (s1, e1) :: t -> xorQueries' t arr ((arr.[e1 + 1] ^^^ arr.[s1]) :: acc)

    let arr =
        arr
        |> List.fold (fun acc n -> ((List.head acc) ^^^ n) :: acc) [ 0 ]
        |> List.rev
        |> List.toArray

    xorQueries' queries arr []