LeetCode 1603: Design Parking System
Problem Description
Explanation:
- We can simply keep track of the number of available parking slots for each car type (big, medium, small) and decrement the count whenever a car of that type parks.
- When a car tries to park, we check if there are available slots for that car type and return true if parking is successful.
- The constraints ensure that we do not need to worry about exceeding the slot limits.
Solutions
class ParkingSystem {
private int[] slots;
public ParkingSystem(int big, int medium, int small) {
this.slots = new int[]{big, medium, small};
}
public boolean addCar(int carType) {
if (slots[carType - 1] > 0) {
slots[carType - 1]--;
return true;
}
return false;
}
}
Loading editor...