LeetCode 1545. Find Kth Bit in Nth Binary String in F#
URL
Code
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)