LeetCode 1603. 设计停车系统
原题链接
简单
作者:
_cc
,
2021-03-19 09:55:30
,
所有人可见
,
阅读 668
C++ 代码
class ParkingSystem {
public:
int num[4]; //分别来存大中小车位
ParkingSystem(int big, int medium, int small) {
num[1]=big;
num[2]=medium;
num[3]=small;
}
bool addCar(int carType) { //carType是对应的停车位
if(num[carType]>=1){ //如果还剩下该车位就减去1,返回true
num[carType]-=1;
return true;
}
return false; //否则返回false
}
};
/**
* Your ParkingSystem object will be instantiated and called as such:
* ParkingSystem* obj = new ParkingSystem(big, medium, small);
* bool param_1 = obj->addCar(carType);
*/