1603. Design Parking System

class ParkingSystem {

    private array $parks = [];

    /**
     * @param Integer $big
     * @param Integer $medium
     * @param Integer $small
     */
    function __construct($big, $medium, $small) {
        $this->parks = [
            1 => $big,
            2 => $medium,
            3 => $small
        ];
    }
  
    /**
     * @param Integer $carType
     * @return Boolean
     */
    function addCar($carType) {
        if($this->parks[$carType] === 0){
            return false;
        }

        $this->parks[$carType]--;
        return true;
    }
}

/**
 * Your ParkingSystem object will be instantiated and called as such:
 * $obj = ParkingSystem($big, $medium, $small);
 * $ret_1 = $obj->addCar($carType);
 */

Last updated