class ParkingSystem {
vector<int>p=vector<int>(3);
public:
ParkingSystem(int big, int medium, int small) {
p[0]=big;
p[1]=medium;
p[2]=small;
}
bool addCar(int carType) {
if(carType==1&&p[0]>0) {p[0]-=1;return true;}
else if(carType==2&&p[1]>0) {p[1]-=1;return true;}
else if(carType==3&&p[2]>0) {p[2]-=1;return true;}
else 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);
*/
力扣每日一题1603 设计停车场
最新推荐文章于 2021-04-01 14:23:17 发布