LeetCode 605. Can Place Flowers in F#

URL

Can Place Flowers - LeetCode

Code

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

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