-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdesignParkingSystem.cpp
More file actions
40 lines (36 loc) · 928 Bytes
/
designParkingSystem.cpp
File metadata and controls
40 lines (36 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Source: https://leetcode.com/problems/design-parking-system/
// Author: Miao Zhang
// Date: 2021-05-20
class ParkingSystem {
public:
ParkingSystem(int big, int medium, int small) : big_(big), medium_(medium), small_(small) {
}
bool addCar(int carType) {
if (carType == 1) {
if (big_ > 0) {
big_--;
return true;
}
} else if (carType == 2) {
if (medium_ > 0) {
medium_--;
return true;
}
} else {
if (small_ > 0) {
small_--;
return true;
}
}
return false;
}
private:
int big_;
int medium_;
int small_;
};
/**
* Your ParkingSystem object will be instantiated and called as such:
* ParkingSystem* obj = new ParkingSystem(big, medium, small);
* bool param_1 = obj->addCar(carType);
*/