算法
......
时间复杂度 O(1)
C++ 代码
class ParkingSystem {
public:
int size[3];
ParkingSystem(int big, int medium, int small) {
size[0] = big;
size[1] = medium;
size[2] = small;
}
bool addCar(int carType) {
if(size[carType-1])
{
size[carType-1]--;
return true;
}
return false;
}
};
/**
* Your ParkingSystem object will be instantiated and called as such:
* ParkingSystem* obj = new ParkingSystem(big, medium, small);
* bool param_1 = obj->addCar(carType);
*/