1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-09-19 17:56:55 +02:00

problems(cpp): add “1603. Design Parking System”

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2023-05-30 00:02:00 +02:00
parent 85a6ee72b0
commit f4bda0ca05
Signed by: mfocko
GPG key ID: 7C47D46246790496

View file

@ -0,0 +1,46 @@
#include <cassert>
class ParkingSystem {
int big;
int medium;
int small;
int& get(int carType)
{
switch (carType) {
case 1:
return big;
case 2:
return medium;
case 3:
return small;
default:
assert(false);
}
}
public:
ParkingSystem(int big, int medium, int small)
: big(big)
, medium(medium)
, small(small)
{
}
bool addCar(int carType)
{
auto& space = get(carType);
if (space <= 0) {
return false;
}
--space;
return true;
}
};
/**
* Your ParkingSystem object will be instantiated and called as such:
* ParkingSystem* obj = new ParkingSystem(big, medium, small);
* bool param_1 = obj->addCar(carType);
*/