Unknown's avatar

1603. Design Parking System

1603. Design Parking System

class ParkingSystem {
 static int big = 0;
 static int medium = 0;
 static int small = 0;
    public ParkingSystem(int big1, int medium1, int small1) {
        big = big1;
        medium = medium1;
        small = small1;
    }
    
    public boolean addCar(int carType) {
        if(carType == 1){
            if(big >= 1){
                big--;
                return true;
            }else return false;
        }else if(carType == 2){
            if(medium >= 1){
                medium--;
                return true;
            } else return false;
        }else if (carType == 3){
            if(small >= 1){
                small--;
                return true;
            }else return false;
        }
        return false;
    }
}

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

Leave a comment