Skip to content

Commit b06bce4

Browse files
authored
Update Design Parking System.java
1 parent ed39e95 commit b06bce4

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

Easy/Design Parking System.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
class ParkingSystem {
2-
int[] slots;
2+
3+
private int[] availableSpaces;
34
public ParkingSystem(int big, int medium, int small) {
4-
slots = new int[]{big, medium, small};
5+
this.availableSpaces = new int[]{big, medium, small};
56
}
67

78
public boolean addCar(int carType) {
8-
if (slots[carType - 1] == 0) {
9-
return false;
10-
}
11-
slots[carType - 1]--;
12-
return true;
9+
return this.availableSpaces[carType - 1]-- > 0;
1310
}
1411
}
1512

0 commit comments

Comments
 (0)