forked from javadev/LeetCode-in-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParkingSystem.java
39 lines (35 loc) · 1010 Bytes
/
ParkingSystem.java
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
package g1601_1700.s1603_design_parking_system;
// #Easy #Design #Simulation #Counting #Programming_Skills_I_Day_12_Class_and_Object
// #2022_04_11_Time_8_ms_(76.16%)_Space_54.3_MB_(65.10%)
public class ParkingSystem {
private final int[] slots = new int[3];
public ParkingSystem(int big, int medium, int small) {
slots[0] = big;
slots[1] = medium;
slots[2] = small;
}
public boolean addCar(int carType) {
if (carType == 1) {
if (slots[0] > 0) {
slots[0]--;
return true;
} else {
return false;
}
} else if (carType == 2) {
if (slots[1] > 0) {
slots[1]--;
return true;
} else {
return false;
}
} else {
if (slots[2] > 0) {
slots[2]--;
return true;
} else {
return false;
}
}
}
}