mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-10 00:09:06 +01:00
problems(cpp): add “1603. Design Parking System”
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
85a6ee72b0
commit
f4bda0ca05
1 changed files with 46 additions and 0 deletions
46
problems/design-parking-system.cpp
Normal file
46
problems/design-parking-system.cpp
Normal 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);
|
||||
*/
|
Loading…
Reference in a new issue