Sunday, February 14, 2021

Leetcode Everyday: 1603. Design Parking System. Easy

public class ParkingSystem {
    
    Dictionary<int, int> _parkSlots = new Dictionary<int, int>();

    public ParkingSystem(int big, int medium, int small) {
        _parkSlots[1] = big;
        _parkSlots[2] = medium;
        _parkSlots[3] = small;
    }
    
    public bool AddCar(int carType) {
        if (_parkSlots[carType] > 0) {
            --_parkSlots[carType];
            return true;
        }
        return false;
    }
}


No comments:

Post a Comment