Skip to content

Latest commit

 

History

History
29 lines (22 loc) · 627 Bytes

1603. 设计停车系统.md

File metadata and controls

29 lines (22 loc) · 627 Bytes
  • 数组
class ParkingSystem {

    private cars: number[];

    constructor(big: number, medium: number, small: number) {
        this.cars = [big, medium, small];
    }

    addCar(carType: number): boolean {
        if (this.cars[carType - 1] <= 0) {
            return false;
        }
        --this.cars[carType - 1];
        return true;
    }
}

/**
 * Your ParkingSystem object will be instantiated and called as such:
 * var obj = new ParkingSystem(big, medium, small)
 * var param_1 = obj.addCar(carType)
 */