Skip to content

Commit 877ffe9

Browse files
authored
Create designparkingsystem.cpp
1 parent 6c7a98c commit 877ffe9

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
class ParkingSystem {
2+
public:
3+
int big;
4+
int medium;
5+
int small;
6+
7+
ParkingSystem(int big, int medium, int small) {
8+
this->big = big;
9+
this->medium = medium;
10+
this->small = small;
11+
}
12+
13+
bool addCar(int carType) {
14+
15+
if(carType == 1 && big == 0 || carType == 2 && medium == 0 || carType == 3 && small == 0)
16+
return false;
17+
18+
if(carType == 1) big--;
19+
if(carType == 2) medium--;
20+
if(carType == 3) small--;
21+
22+
return true;
23+
}
24+
};
25+
26+
/**
27+
* Your ParkingSystem object will be instantiated and called as such:
28+
* ParkingSystem* obj = new ParkingSystem(big, medium, small);
29+
* bool param_1 = obj->addCar(carType);
30+
31+
O(1)
32+
*/

0 commit comments

Comments
 (0)