LeetCode 1545. Find Kth Bit in Nth Binary String in F#

URL

https://leetcode.com/problems/find-kth-bit-in-nth-binary-string/description/?envType=daily-question&envId=2024-10-19

Code

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

let findKthBit (n: int) (k: int) : char =
    if n = 1 then
        '0'
    else
        seq { 2..n }
        |> Seq.fold
            (fun acc _ ->
                acc
                @ [ '1' ]
                @ (acc |> List.rev |> List.map (fun n -> if n = '1' then '0' else '1')))
            [ '0' ]
        |> List.item (k - 1)