2024每日刷题(122)
Leetcode—1603. 设计停车系统
实现代码
class ParkingSystem {
public:
ParkingSystem(int big, int medium, int small) {
m_big = big;
m_medium = medium;
m_small = small;
}
bool addCar(int carType) {
switch(carType) {
case 1:
{
if(m_big) {
m_big--;
return true;
}
return false;
}
case 2:
{
if(m_medium) {
m_medium--;
return true;
}
return false;
}
case 3:
{
if(m_small) {
m_small--;
return true;
}
return false;
}
}
return true;
}
private:
int m_big = 0;
int m_medium = 0;
int m_small = 0;
};
/**
* Your ParkingSystem object will be instantiated and called as such:
* ParkingSystem* obj = new ParkingSystem(big, medium, small);
* bool param_1 = obj->addCar(carType);
*/
运行结果
之后我会持续更新,如果喜欢我的文章,请记得一键三连哦,点赞关注收藏,你的每一个赞每一份关注每一次收藏都将是我前进路上的无限动力 !!!↖(▔▽▔)↗感谢支持!