LeetCode 605. Can Place Flowers in F#
URL
Code
let canPlaceFlowers (floweredbed: int list) (n: int) : bool =
let v = (0 :: floweredbed) @ [ 0 ]
let flowers =
v
|> List.windowed 3
|> List.fold
(fun acc w ->
match w with
| a :: b :: c :: [] ->
if b = 0 then
if a = 0 && c = 0 then acc + 1 else acc
else
acc
| _ -> failwith "never reach here")
0
flowers >= n