Skip to content

1603. Design Parking System 👍

  • Time: $O(1)$
  • Space: $O(1)$
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
class ParkingSystem {
 public:
  ParkingSystem(int big, int medium, int small) {
    count = {big, medium, small};
  }

  bool addCar(int carType) {
    return count[carType - 1]-- > 0;
  }

 private:
  vector<int> count;
};
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
class ParkingSystem {
  public ParkingSystem(int big, int medium, int small) {
    count = new int[] {big, medium, small};
  }

  public boolean addCar(int carType) {
    return count[carType - 1]-- > 0;
  }

  private int[] count;
}
1
2
3
4
5
6
7
class ParkingSystem:
  def __init__(self, big: int, medium: int, small: int):
    self.count = [big, medium, small]

  def addCar(self, carType: int) -> bool:
    self.count[carType - 1] -= 1
    return self.count[carType - 1] >= 0