-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDesignParkingSystem.cpp
More file actions
36 lines (34 loc) · 1.07 KB
/
DesignParkingSystem.cpp
File metadata and controls
36 lines (34 loc) · 1.07 KB
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
// https://leetcode.com/problems/design-parking-system/submissions/
// Time complexity of addCar: O(1)
class ParkingSystem {
public:
public: vector<int> vehicle;
public:
ParkingSystem(int big, int medium, int small) {
vehicle = {big, medium, small};
}
bool addCar(int carType) {
// for each small car, check if small car spots are availablem if so, return true and decrease the count of available spots
if(carType == 1) {
if(vehicle[0] > 0){
vehicle[0]--;
return true;
}
}
// for each medium car, check if medium car spots are availablem if so, return true and decrease the count of available medium spots
else if(carType == 2) {
if(vehicle[1] > 0){
vehicle[1]--;
return true;
}
}
// same logic as above but for big cars
else if(carType == 3) {
if(vehicle[2] > 0){
vehicle[2]--;
return true;
}
}
return false;
}
};