LeetCode 1603. Design Parking System in F#

URL

Design Parking System - LeetCode

Code

https://github.com/syohex/dotnet-study/tree/master/fsharp/leetcode/problems/1603/main.fsx

type ParkingSystem =
    { cars: int[] }

    static member init (big: int) (medium: int) (small: int) : ParkingSystem =
        let cars = [| big; medium; small |]
        { cars = cars }

    static member addCar (carType: int) (p: ParkingSystem) : (bool * ParkingSystem) =
        let index = carType - 1

        if p.cars.[index] = 0 then
            false, p
        else
            p.cars.[index] <- p.cars.[index] - 1
            true, p